Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task #228793 chore: Logs implenetation for import ucm functionality #426

Open
wants to merge 4 commits into
base: j4x
Choose a base branch
from

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

Copy link

sonarcloud bot commented Oct 16, 2024

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