Skip to content

Revert "Potential fix for code scanning alert no. 3: Uncontrolled data used in path expression"#12

Merged
KyFaSt merged 1 commit intomainfrom
revert-9-alert-autofix-3
Jan 12, 2026
Merged

Revert "Potential fix for code scanning alert no. 3: Uncontrolled data used in path expression"#12
KyFaSt merged 1 commit intomainfrom
revert-9-alert-autofix-3

Conversation

@KyFaSt
Copy link
Copy Markdown
Collaborator

@KyFaSt KyFaSt commented Jan 12, 2026

Reverts #9

Copilot AI review requested due to automatic review settings January 12, 2026 17:16
@KyFaSt KyFaSt merged commit 1290e76 into main Jan 12, 2026
3 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request reverts a previous security fix that addressed a path traversal vulnerability in the file download API endpoint. The revert removes secure path validation logic and reintroduces the intentional vulnerability for educational/demonstration purposes in this GitHub Advanced Security demo repository.

Changes:

  • Removed secure path validation that prevented path traversal attacks
  • Reintroduced direct use of user input in file path construction
  • Added explicit vulnerability warning comments

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +18 to +22
const filePath = path.join(process.cwd(), 'uploads', filename);

try {
const fileContent = fs.readFileSync(resolvedPath, 'utf8');
// Reading file without proper validation
const fileContent = fs.readFileSync(filePath, 'utf8');
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

This code reintroduces a critical path traversal vulnerability. The filename parameter from user input is directly used in path construction without validation, allowing attackers to access files outside the intended uploads directory using sequences like "../../../etc/passwd". The path.join function does not prevent path traversal attacks. The removed security checks (path.resolve with startsWith validation) were correctly preventing this vulnerability and should be restored.

See below for a potential fix:

  // Securely construct and validate the file path to prevent path traversal
  const uploadsDir = path.resolve(process.cwd(), 'uploads');
  const resolvedPath = path.resolve(uploadsDir, filename);

  // Ensure the resolved path is within the uploads directory
  if (!resolvedPath.startsWith(uploadsDir + path.sep)) {
    return res.status(400).json({ error: 'Invalid filename' });
  }
  
  try {
    // Reading file after proper validation
    const fileContent = fs.readFileSync(resolvedPath, 'utf8');

Copilot uses AI. Check for mistakes.
@LadyKerr LadyKerr deleted the revert-9-alert-autofix-3 branch January 20, 2026 19:09
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