Skip to content

Conversation

@ohgodwhy2k
Copy link
Owner

Potential fix for https://github.com/ohgodwhy2k/quicksite/security/code-scanning/1

To fix the problem, we need to validate the path derived from user input such that only files strictly underneath the project's DIST_ROOT can be served. This is best done by:

  1. Constructing the target path with path.resolve() (after joining with the root), canonicalizing removal of .., etc.
  2. Comparing the resulting absolute, normalized path to ensure it starts with the known absolute path for DIST_ROOT.
  3. Only serve files when this check passes, otherwise respond with a 403 Forbidden or 404.

Update the scripts/serve.js in the handler for requests:

  • At the top of the file, compute the canonical absolute path to DIST_ROOT once.
  • Resolve requested file paths with path.resolve(), using canonical DIST_ROOT as the base.
  • Before reading any file, check if the resolved path starts with the absolute DIST_ROOT path.
  • If not, respond with a 403 forbidden and terminate the request.

You will also need to add an import for resolve and normalize if not already present (although resolve is available from node:path).


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

ohgodwhy2k and others added 2 commits November 21, 2025 16:57
…n path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@ohgodwhy2k ohgodwhy2k closed this Nov 21, 2025
@ohgodwhy2k ohgodwhy2k deleted the alert-autofix-1 branch November 22, 2025 01:31
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