Skip to content

Normalize E2E base-path handling and harden static file serving in run_e2e.mjs - #6

Merged
yf-1229 merged 3 commits into
masterfrom
copilot/fix-code-for-review-comments
Aug 1, 2026
Merged

yf-1229 merged 3 commits into
masterfrom
copilot/fix-code-for-review-comments

Conversation

Copilot AI commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

This PR addresses review-thread feedback on web/e2e/run_e2e.mjs: E2E_BASE_PATH handling was brittle for slash variants, and request-path handling could throw on missing URLs and allow traversal outside dist/. It updates path normalization and request resolution so subpath E2E runs are robust and constrained to the build output root.

  • Base-path normalization

    • Added normalization for E2E_BASE_PATH so inputs like /coBroc, coBroc/, and /coBroc/ resolve consistently to /coBroc.
    • Ensures prefix stripping logic behaves consistently for subpath simulation.
  • Request URL safety

    • Guarded against undefined/empty req.url with a stable default ('/').
    • Normalized incoming path shape before further processing.
  • Traversal protection for static serving

    • Switched to resolved absolute paths from a fixed DIST_ROOT.
    • Added boundary check to reject requests that resolve outside dist/ with 403.
const BASE_PATH = normalizeBasePath(process.env.E2E_BASE_PATH || '');
let urlPath = (req.url ?? '/').split('?')[0] || '/';

const p = resolve(DIST_ROOT, `.${urlPath === '/' ? '/index.html' : urlPath}`);
if (p !== DIST_ROOT && !p.startsWith(`${DIST_ROOT}${sep}`)) {
  res.writeHead(403);
  res.end();
  return;
}

Copilot AI changed the title [WIP] Fix code for all comments in review thread Normalize E2E base-path handling and harden static file serving in run_e2e.mjs Aug 1, 2026
Copilot AI requested a review from yf-1229 August 1, 2026 02:40
@yf-1229
yf-1229 marked this pull request as ready for review August 1, 2026 02:45
Copilot AI review requested due to automatic review settings August 1, 2026 02:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the web/e2e/run_e2e.mjs E2E runner’s static server to behave consistently when simulating GitHub Pages-style subpaths and to constrain static file resolution to the dist/ output directory.

Changes:

  • Normalizes E2E_BASE_PATH to a consistent '' or '/name' form (no trailing slash).
  • Hardens request URL handling by defaulting missing req.url to '/' and normalizing to a leading /.
  • Switches static serving to resolve() + DIST_ROOT boundary checks to prevent path traversal outside dist/.

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

Comment thread web/e2e/run_e2e.mjs
Comment thread web/e2e/run_e2e.mjs
Comment on lines +49 to 53
return;
}
if (!existsSync(p)) { res.writeHead(404); res.end(); return; }
const ext = extname(p);
res.writeHead(200, { 'Content-Type': mime[ext] || 'application/octet-stream' });
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@yf-1229
yf-1229 merged commit 9d185f4 into master Aug 1, 2026
1 check failed
@yf-1229
yf-1229 deleted the copilot/fix-code-for-review-comments branch August 1, 2026 07:39
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.

3 participants