fix(website): escape vulnerability IDs in hierarchy display#5228
Merged
michaelkedar merged 2 commits intogoogle:masterfrom Apr 13, 2026
Merged
fix(website): escape vulnerability IDs in hierarchy display#5228michaelkedar merged 2 commits intogoogle:masterfrom
michaelkedar merged 2 commits intogoogle:masterfrom
Conversation
construct_hierarchy_string() in gcp/website/frontend_handlers.py builds the upstream/downstream hierarchy HTML for vulnerability pages by concatenating raw vuln_id strings into <li> and <a href=...> fragments. The result is rendered with Jinja2's |safe filter, so any non-ASCII markup characters that reach this code path would be emitted verbatim. Wrap each id with markupsafe.escape and assemble the output as markupsafe.Markup so that ids drawn from source records are always HTML-escaped in the rendered hierarchy, matching how the rest of the template handles data-derived text. Adds unit tests in frontend_handlers_test.py covering the known-id, unknown-id, and plain-id code paths.
Member
|
/gcbrun |
tymzd
pushed a commit
to tymzd/osv.dev
that referenced
this pull request
Apr 13, 2026
) ## Summary `construct_hierarchy_string()` in `gcp/website/frontend_handlers.py` builds the upstream/downstream hierarchy HTML for vulnerability pages by concatenating raw `vuln_id` strings into `<li>` and `<a href=...>` fragments. The resulting string is rendered with Jinja2's `| safe` filter in `vulnerability.html`, so any markup characters that reach this code path are emitted verbatim. This PR wraps each id with `markupsafe.escape` and assembles the output as `markupsafe.Markup`, so ids drawn from source records are always HTML-escaped in the rendered hierarchy — matching how the rest of the template handles data-derived text. ## Changes - `gcp/website/frontend_handlers.py` — `construct_hierarchy_string` now returns `Markup`; each `vuln_id` is passed through `escape()` before being spliced into the `<li>` / `<a>` fragments, using `Markup(...).format(...)` so nested `Markup` fragments compose safely. - `gcp/website/frontend_handlers_test.py` — new `ConstructHierarchyStringTest` with three cases: - a known id containing `<script>` — verified not present verbatim, present as `<script>` - an unknown id containing `"><img ...>` — verified escaped - a plain `CVE-2024-0001` — verified the anchor still renders identically to before ## Testing - `python3 -m unittest frontend_handlers_test.ConstructHierarchyStringTest` — passes locally against the patched function. - Existing hierarchy rendering is byte-identical for ids containing only `[A-Za-z0-9:._-]`, so no change is expected for any well-formed OSV id. --------- Co-authored-by: TristanInSec <tristan.mtn@gmail.com>
Contributor
Author
|
PS: This PR fixes the issue reported in https://issuetracker.google.com/issues/502293433 |
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
construct_hierarchy_string()ingcp/website/frontend_handlers.pybuilds the upstream/downstream hierarchy HTML for vulnerability pages by concatenating rawvuln_idstrings into<li>and<a href=...>fragments. The resulting string is rendered with Jinja2's| safefilter invulnerability.html, so any markup characters that reach this code path are emitted verbatim.This PR wraps each id with
markupsafe.escapeand assembles the output asmarkupsafe.Markup, so ids drawn from source records are always HTML-escaped in the rendered hierarchy — matching how the rest of the template handles data-derived text.Changes
gcp/website/frontend_handlers.py—construct_hierarchy_stringnow returnsMarkup; eachvuln_idis passed throughescape()before being spliced into the<li>/<a>fragments, usingMarkup(...).format(...)so nestedMarkupfragments compose safely.gcp/website/frontend_handlers_test.py— newConstructHierarchyStringTestwith three cases:<script>— verified not present verbatim, present as<script>"><img ...>— verified escapedCVE-2024-0001— verified the anchor still renders identically to beforeTesting
python3 -m unittest frontend_handlers_test.ConstructHierarchyStringTest— passes locally against the patched function.[A-Za-z0-9:._-], so no change is expected for any well-formed OSV id.