Commit fb9be92
fix(website): escape vulnerability IDs in hierarchy display (#5228)
## 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>1 parent eeb4e82 commit fb9be92
2 files changed
Lines changed: 53 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1103 | 1103 | | |
1104 | 1104 | | |
1105 | 1105 | | |
1106 | | - | |
| 1106 | + | |
1107 | 1107 | | |
1108 | 1108 | | |
1109 | 1109 | | |
| |||
1112 | 1112 | | |
1113 | 1113 | | |
1114 | 1114 | | |
1115 | | - | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
1116 | 1119 | | |
1117 | | - | |
| 1120 | + | |
1118 | 1121 | | |
1119 | 1122 | | |
1120 | 1123 | | |
| |||
1126 | 1129 | | |
1127 | 1130 | | |
1128 | 1131 | | |
| 1132 | + | |
1129 | 1133 | | |
1130 | | - | |
1131 | | - | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
1132 | 1137 | | |
1133 | | - | |
| 1138 | + | |
1134 | 1139 | | |
1135 | 1140 | | |
1136 | 1141 | | |
1137 | 1142 | | |
1138 | 1143 | | |
1139 | | - | |
| 1144 | + | |
1140 | 1145 | | |
1141 | | - | |
| 1146 | + | |
1142 | 1147 | | |
1143 | 1148 | | |
1144 | 1149 | | |
1145 | | - | |
| 1150 | + | |
1146 | 1151 | | |
1147 | | - | |
| 1152 | + | |
1148 | 1153 | | |
1149 | | - | |
1150 | | - | |
| 1154 | + | |
1151 | 1155 | | |
1152 | 1156 | | |
1153 | 1157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
160 | 197 | | |
161 | 198 | | |
162 | 199 | | |
| |||
0 commit comments