Skip to content

Conversation

@punambaravkar
Copy link
Contributor

No description provided.

header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($logFilePath));

Check failure

Code scanning / SonarCloud

I/O function calls should not be vulnerable to path injection attacks High

Change this code to not construct the path from user-controlled data. See more on SonarCloud
flush();

// Read and output the file content
readfile($logFilePath);

Check failure

Code scanning / SonarCloud

I/O function calls should not be vulnerable to path injection attacks High

Change this code to not construct the path from user-controlled data. See more on SonarCloud
*/
public function downloadLog()
{
$logFileName = Factory::getApplication()->input->getString('file');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@punambaravkar
Take only file name from input and use it.
// Use basename() to extract only the filename, preventing directory traversal. and use it in the next lines
$safeFileName = basename(logFileName);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
$logFileName = Factory::getApplication()->input->getString('file');

// Full path to the log file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@punambaravkar

// Construct the full path.
$baseDir = JPATH_ADMINISTRATOR . '/logs/'
$fullPath = realpath($baseDir . $safeFileName);

    // Validate: Ensure the path is within the intended directory.
    if (strpos($fullPath, $baseDir) !== 0 || !$fullPath) 
    {
        JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
        return false;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants