Commit 9b240f2
committed
fix: remove empty anchor tags from GHSA vulnerability details
Fixes issue where empty anchor tags like <a name="executive-summary"></a>
were appearing in GHSA vulnerability details fields. These anchor tags
are used for navigation in the original GHSA advisories but create empty
links when displayed in OSV records. This affects 51 GHSA records,
including NuGet packages.
The fix is implemented at two layers for defense in depth:
1. Data layer (osv/sources.py):
- Add _sanitize_anchor_tags() function to remove empty anchor tags
with name attributes using regex pattern matching
- Apply sanitization in parse_vulnerability_from_dict() to clean
the details field during vulnerability parsing
- Ensures anchor tags are removed when GHSA JSON files are imported
2. Display layer (gcp/website/frontend_handlers.py):
- Add _ANCHOR_TAG_REPLACER regex pattern for anchor tag removal
- Apply sanitization in markdown() template filter during rendering
- Provides fallback protection if any anchor tags slip through
3. Emulator update (gcp/website/frontend_emulator.py):
- Update to use parse_vulnerability_from_dict() instead of direct
json_format.ParseDict() to ensure sanitization is applied during
local testing
Testing:
- Verified fix removes all 7 anchor tags from GHSA-hh2w-p6rv-4g7w test case
- Tested with various anchor tag formats (empty, self-closing, with attributes)
- Confirmed regular links and anchor tags with content are preserved
- Local testing performed using direct function tests and file parsing
(gcloud emulator setup unavailable due to permission issues with
~/.config/gcloud directory ownership)
Signed-off-by: Vasu <[email protected]>1 parent 393b8fb commit 9b240f2
File tree
3 files changed
+19
-2
lines changed- gcp/website
- osv
3 files changed
+19
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
94 | 93 | | |
95 | | - | |
| 94 | + | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
834 | 834 | | |
835 | 835 | | |
836 | 836 | | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
837 | 840 | | |
838 | 841 | | |
839 | 842 | | |
| |||
852 | 855 | | |
853 | 856 | | |
854 | 857 | | |
| 858 | + | |
855 | 859 | | |
856 | 860 | | |
857 | 861 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
165 | 173 | | |
166 | 174 | | |
167 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
168 | 181 | | |
169 | 182 | | |
170 | 183 | | |
| |||
0 commit comments