Fix the two regex defects CodeQL flags in the build script - #17
Merged
Merged
Conversation
The script-tag regex missed end tags written as `</script >`, so such a tag would have been dropped from the bundle without warning. The exclude-pattern builder escaped only dots, leaving every other regex metacharacter live, and passed "g" as a third argument to String.replace, where it is ignored -- only the first `*` of a pattern became `.*`, so `*foo*` compiled to `.*foo*`, which matches `.*fo` followed by zero or more `o`. Escape the full metacharacter set and make the wildcard substitution global. Both are latent: the current exclude list and index.html produce byte -identical output before and after.
\s* covered whitespace but not </script/> or </script bar>, both of which browsers accept, so CodeQL still reported the regex as incomplete. [^>]* covers all of them. The build output is unchanged either way.
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
CodeQL's first scan of
mainraised ten alerts. Eight are in the vendoreddocs/node-jsdoc-toolkit/documentation generator; the two in our own build script are addressed here.js/incomplete-sanitization(Jakefile.js:110) — a real bug. The exclude-pattern builder escaped only dots, leaving+ ? ^ $ { } ( ) | [ ] \live in patterns compiled straight into aRegExp. It also passed"g"as a third argument toString.prototype.replace, which takes two and ignores the rest, so with a string pattern only the first*was converted.*foo*compiled to.*foo*— that is.*fofollowed by zero or moreo, not the intended wildcard.js/bad-tag-filter(Jakefile.js:17) — the script-tag regex accepted only a bare</script>. It now accepts every browser-tolerated end-tag form via[^>]*, so a tag written as</script >or</script/>can no longer be dropped from the bundle in silence.Note that CodeQL still reports the line 17 regex. The rule targets HTML sanitizers fed untrusted input; this is a build-time extractor over our own
src/index.html, and the regex requires an opening tag, so it can never match a bare</script >no matter how the end-tag part is written. The change is a robustness improvement, not a security fix, and the remaining alert looks like a false positive for this code shape.The build output does not change
Both defects are latent against today's inputs, verified rather than assumed:
index.html, and the 44 script paths in theJS:LIBsection) produce a byte-identical pattern under the old and new escaping.src/index.html.dist/are byte-identical before and after. The 26th iscache.appcache, which embedsDate.now()atJakefile.js:149and so differs between any two builds; stripped of its timestamp line it hashes identically too.dist/js/script.jsstays ata3a26210ce5e662136417e436b5e75ba36a80e68bcd0e90f34602d378faedd26, so the hash eXeLearning pins is untouched and noPINNED_REVISIONbump is implied.npm testpasses (13 assertions).Scope
Build script only. No dependency, application-source or CI changes. These files are identical to
drichard/mindmaps:master, so this could become a later upstream candidate if the maintainer wants it.