Skip to content

Stop interpolating archive paths into inline handlers - #470

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/browse-xss
Oct 14, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/browse-xss

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

The source browser built its file tree with inline handlers such as onclick="loadFile('${escapeHTML(file.path)}')". The browser decodes HTML entities in an attribute value before it runs the handler, so the ' that escapeHTML produces turns back into ' and ends the JS string. Once a package with a crafted file name in its archive (e.g. a');alert(1);//) is cached, opening it in /ui/package/... runs that script on the proxy origin.

Changes

  • File tree entries carry their path in data-action / data-path, and one delegated click listener on #file-tree dispatches to loadFileTree / loadFile. The path now only ever sits in HTML attribute context, where escapeHTML is sufficient.
  • The binary-file "Download" button is a styled <a href> instead of an onclick that sets window.location.
  • No behaviour change: the back entry, directory navigation and currentPath updates work as before.

Testing

  • New TestTemplatesInterpolateNoDataIntoInlineHandlers scans every embedded template for an on*="…${ attribute. Before the fix it found the 4 handlers in browse_source.html.
  • go test -race ./internal/server/..., go vet and golangci-lint v2.13.1 pass.

The source browser built its file tree with onclick handlers such as
loadFile('${escapeHTML(file.path)}'). The browser decodes HTML entities in
an attribute before running the handler, so the &git-pkgs#39; that escapeHTML
produces turns back into a quote and ends the string. A cached package
with a crafted file name ran script on the proxy origin for anyone who
browsed it.

- Carry the path in data-path and dispatch clicks from one delegated
  listener on the file tree
- Render the binary download button as a link instead of an onclick
  that assigns window.location
- Fail the template tests when an inline handler interpolates data
@andrew
andrew merged commit 3201493 into git-pkgs:main Oct 14, 2026
6 checks passed
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