Fix g-flag regex in getValidId and CSS selector injection in getIdFromUrl#1558
Conversation
…n getIdFromUrl (aframevr/aframe-inspector#853) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Code Review for PR 1558 - see detailed review below |
|
Code Review - PR 1558 Note: replacing placeholder comment above Overview: This PR backports bug fixes from aframe-inspector#853 into 3DStreet, addressing: (1) a CSS selector injection vulnerability in getIdFromUrl, (2) missing g-flag on two regexes in getValidId, and (3) expanding isValidId to allow underscore as the first character. Security Fix - getIdFromUrl Correct and important fix. The old code concatenated url directly into a CSS attribute selector -- a URL containing a single quote could break out of the selector quotes or cause unexpected CSS injection behavior. The fix escapes single quotes before interpolation, which is correct and sufficient for this context. Regex Bug Fixes - getValidId Both missing g flags were real bugs causing only the first match to be replaced:
Examples that were silently broken before:
isValidId - Consistent Expansion Good fix. \w already matches underscore, so getValidId could produce IDs starting with underscore (e.g. from '_asset.png'), but the old isValidId would reject them. This change aligns the validator with the generator. Suggestions
Summary
The changes are correct and low-risk. Adding unit tests would lock in the expected behavior and prevent regressions, but the core fixes are solid and ready to merge. |
Backport of aframevr/aframe-inspector#853
This addresses summary point 3 #1540 (comment)