JS: experimental query for a multi-character pattern applied to a single stream chunk - #22738
Open
ninadphalak wants to merge 1 commit into
Open
ninadphalak wants to merge 1 commit into
ninadphalak wants to merge 1 commit into
Conversation
… single stream chunk A regular expression that can match two or more characters, applied to one chunk of a stream with nothing carried from the previous chunk, never sees a value that straddles two chunks. Flags per-chunk callbacks (Transform, TransformStream, 'data' listeners, for-await loops) where the chunk flows to such a pattern. Includes query help, examples and a test.
This branch has not been deployed
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
Adds
javascript/ql/src/experimental/Security/CWE-693/SplitBoundaryChunkFilter.ql(
js/split-boundary-chunk-filter, path-problem, precision medium) with query help, examplesand a test.
A stream arrives in chunks whose boundaries are chosen by the sender or transport. A filter
that applies a regular expression to each chunk on its own never sees a value that straddles
two chunks, so a redaction filter forwards it and a blocking filter lets it through. Whole-string
tests pass, which is why the defect survives review. It was found and fixed independently in
several streaming guardrail frameworks this year and reappears in general stream replacers and
secret scanners; the mechanism is the one described for network intrusion detection in 1998.
What the query does
Transform/Writable(
_transform,_write, or thetransform/writeoption), webTransformStreamtransformers,
through2-style callbacks,'data'listeners, andfor awaitloop variables;plus the
partof a MastraprocessOutputStreamprocessor as one framework example.toString/trim/decode/Stringand across calls.
replace,replaceAll,match,matchAll,search,splitwith a regularexpression that can match two or more characters (resolved through
RegExp::getRegExpFromNode),and
test/exec; fortest/execwith an unresolvable receiver the alert says the patternwidth is unknown.
tail + chunk), or toan accumulated buffer, because data flow does not pass through string concatenation. That is
the fix shape the help recommends.
Evaluation
single-character pattern, non-stream code, pattern on an unrelated string) not flagged.
pii-detector.ts. No results on any, and thatis correct: the original per-chunk version used an LLM call rather than a regular expression,
and the later revisions carry a tail. I have no confirmed open-source hit for the regex form
yet; the query encodes the defect class, and I would welcome pointers to projects to run it on.
Checklist
.expectedgenerated bycodeql test runcodeql query formathappy to add if required