fix(export): harden HTML export against XSS via adversarial identifiers#48
Merged
Conversation
…rs (#42) The JSON payload was embedded inline as `const DATA = {payload}`, which let a `</script>` substring in any artifact label break out of the script context. Escape `<`, `>`, `&` (and U+2028/U+2029) to `\uXXXX` in the JSON, and move the payload into a `<script type="application/json">` data tag parsed via `JSON.parse(textContent)`. Closes #42 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Resolves CI lint failures: rustfmt wanted multi-line asserts for the long error messages, and clippy's items-after-test-module triggered because the test block sat above `build_package_html`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<,>,&(and U+2028/U+2029) to\uXXXXin the JSON payload before embedding in HTML — these never legally appear outside string contents inserde_jsonoutput, so the escaped output is still valid JSON that round-trips throughJSON.parse.<script type="application/json" id="grafly-data">…</script>data tag, parsed viaJSON.parse(document.getElementById('grafly-data').textContent). Defense in depth: the data tag never executes as JS, and the escape would neutralise a</script>breakout even if it did.SECURITY.md: removed the Known-limitation entry; added a Threat-surface row describing the mitigation.Closes #42
Test plan
cargo test -p grafly-export— 4 new unit tests cover:</script>breakout neutralisation, ampersand escape, serde JSON round-trip, and end-to-end rendered HTML containing no raw<in the data payload.cargo test --workspace— full suite green.cargo build --release— clean.grafly analyze .smoke test — generatedgrafly_artifacts.html,grafly_modules.html,grafly_packages.htmlall contain the newgrafly-datadata tag.