Skip to content

Conversation

@antonym
Copy link
Member

@antonym antonym commented Feb 13, 2025

Potential fix for https://github.com/netbootxyz/webapp/security/code-scanning/6

To fix the problem, we need to ensure that the filename is validated and sanitized before being used to construct file paths. We can achieve this by normalizing the path and ensuring it is contained within the intended directory. We will use the path module to resolve the path and check that it starts with the root directory.

  1. Normalize the filename using path.resolve to remove any .. segments.
  2. Check that the normalized path starts with the intended root directory.
  3. If the path is invalid, return an error or handle it appropriately.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Ensure constructed file path is contained within a safe root folder.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@antonym antonym changed the title Potential fix for code scanning alert no. 6: Uncontrolled data used in path expression Uncontrolled data used in path expression Feb 13, 2025
@antonym antonym marked this pull request as ready for review February 13, 2025 03:56
@antonym antonym merged commit 8380c6f into master Feb 13, 2025
4 checks passed
@antonym antonym deleted the file-path-validation branch February 13, 2025 03:56
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