-
Notifications
You must be signed in to change notification settings - Fork 1.7k
JS: new Quality
query - Unhandled errors in .pipe()
chain
#19544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
c27157f
Add `UnhandledStreamPipee` Quality query and tests to detect missing …
Napalys f39bf62
test: Add edge cases for stream pipe error handling
Napalys ef1bde5
Fixed issue where streams would not be tracked via chainable methods
Napalys 30f2815
Fixed issue where a custom `pipe` method which returns non stream wou…
Napalys 03d1f9a
Restrict pipe detection to calls with 1-2 arguments
Napalys 5710f0c
Add test cases for non-stream field accesses and methods before and a…
Napalys 4332de4
Eliminate false positives by detecting non-stream objects returned fr…
Napalys d7f86db
Enhance PipeCall to exclude non-function and non-object arguments in …
8000
Napalys 09220fc
Fixed issue where `pipe` calls from `rxjs` package would been identif…
Napalys b104871
Added `UnhandledStreamPipe` to `javascript-security-and-quality.qls` …
Napalys 5b1af0c
Added detection of custom `gulp-plumber` sanitizer, thus one would no…
Napalys ac24fdd
Add predicate to detect non-stream-like usage in sources of pipe calls
Napalys e6ae8bb
Added test cases where second parameter passed to `pipe` is a functio…
Napalys b10a948
Fixed false positives from `strapi` and `rxjs/testing` as well as whe…
Napalys 15ff7cb
Added more test cases which common `js` libraries uses `.pipe()`
Napalys c6db32e
Add exceptions for `arktype`, `execa`, and `highland` to prevent them…
Napalys 248f83c
Added `qhelp` for `UnhandledStreamPipe` query
Napalys 000e69f
Replaced fuzzy `NonNodeStream` MaD to a ql predicate to deal easier w…
Napalys e964b17
Added `maintainability` and `error-handling` tags
Napalys 5214cc0
Excluded `ngrx`, `datorama`, `angular`, `react` and `langchain` from …
Napalys 5bb29b6
Now flags only `.pipe` calls which have an error somewhere down the s…
Napalys f8f5d8f
Exclude `.pipe` detection which are in a test file.
Napalys 2e2b9a9
Make predicates private and clarify stream reference naming.
Napalys d3b2a57
Fixed ql warning `Expression can be replaced with a cast`
Napalys f843cc0
Fix false positives in stream pipe analysis by improving error handle…
Napalys 298ef9a
Now able to track error handler registration via instance properties
Napalys 3cbc414
Update javascript/ql/src/Quality/UnhandledStreamPipe.ql
Napalys 64f00fd
Update javascript/ql/src/Quality/UnhandledStreamPipe.ql
Napalys abd446a
Update javascript/ql/src/Quality/UnhandledStreamPipe.ql
Napalys 7198372
Update javascript/ql/src/Quality/UnhandledStreamPipe.qhelp
Napalys d43695c
Update javascript/ql/src/Quality/UnhandledStreamPipe.qhelp
Napalys ae74edb
Update javascript/ql/src/Quality/UnhandledStreamPipe.ql
Napalys bf2f19d
Update UnhandledStreamPipe.ql
Napalys 7993f7d
Update `qhelp` example to more accurately demonstrate flagged cases
Napalys 8ba1f3f
Update javascript/ql/src/Quality/UnhandledStreamPipe.qhelp
Napalys f6e7059
Merge branch 'main' into js/quality/stream_pipe
Napalys d186994
Renamed `UnhandledStreamPipe.ql` to a better fitting name and ID
Napalys 8521c53
Renamed test directory to match the query name
Napalys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Now flags only
.pipe
calls which have an error somewhere down the s…
…tream, but not on the source stream.
- Loading branch information
commit 5bb29b6e33ceebd152c1e14144c059190cf90d44
There are no files selected for viewing
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
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
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
113 changes: 113 additions & 0 deletions
113
javascript/ql/test/query-tests/Quality/UnhandledStreamPipe/tst.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
const fs = require('fs'); | ||
const zlib = require('zlib'); | ||
|
||
function foo(){ | ||
const source = fs.createReadStream('input.txt'); | ||
const gzip = zlib.createGzip(); | ||
const destination = fs.createWriteStream('output.txt.gz'); | ||
source.pipe(gzip).pipe(destination); // $Alert | ||
gzip.on('error', e); | ||
} | ||
class StreamWrapper { | ||
constructor() { | ||
this.outputStream = getStream(); | ||
} | ||
} | ||
|
||
function zip() { | ||
const zipStream = createWriteStream(zipPath); | ||
let wrapper = new StreamWrapper(); | ||
let stream = wrapper.outputStream; | ||
stream.on('error', e); | ||
stream.pipe(zipStream); | ||
zipStream.on('error', e); | ||
} | ||
|
||
function zip1() { | ||
const zipStream = createWriteStream(zipPath); | ||
let wrapper = new StreamWrapper(); | ||
wrapper.outputStream.pipe(zipStream); // $SPURIOUS:Alert | ||
wrapper.outputStream.on('error', e); | ||
zipStream.on('error', e); | ||
} | ||
|
||
function zip2() { | ||
const zipStream = createWriteStream(zipPath); | ||
let wrapper = new StreamWrapper(); | ||
let outStream = wrapper.outputStream.pipe(zipStream); // $Alert | ||
outStream.on('error', e); | ||
} | ||
|
||
function zip3() { | ||
const zipStream = createWriteStream(zipPath); | ||
let wrapper = new StreamWrapper(); | ||
wrapper.outputStream.pipe(zipStream); // $Alert | ||
zipStream.on('error', e); | ||
} | ||
C700 |
|
|
function zip3() { | ||
const zipStream = createWriteStream(zipPath); | ||
let wrapper = new StreamWrapper(); | ||
let source = getStream(); | ||
source.pipe(wrapper.outputStream); // $MISSING:Alert | ||
wrapper.outputStream.on('error', e); | ||
} | ||
|
||
function zip4() { | ||
const zipStream = createWriteStream(zipPath); | ||
let stream = getStream(); | ||
let output = stream.pipe(zipStream); // $Alert | ||
output.on('error', e); | ||
} | ||
|
||
class StreamWrapper2 { | ||
constructor() { | ||
this.outputStream = getStream(); | ||
this.outputStream.on('error', e); | ||
} | ||
|
||
} | ||
function zip5() { | ||
const zipStream = createWriteStream(zipPath); | ||
let wrapper = new StreamWrapper2(); | ||
wrapper.outputStream.pipe(zipStream); // $SPURIOUS:Alert | ||
zipStream.on('error', e); | ||
} | ||
|
||
class StreamWrapper3 { | ||
constructor() { | ||
this.stream = getStream(); | ||
} | ||
pipeIt(dest) { | ||
return this.stream.pipe(dest); | ||
} | ||
register_error_handler(listener) { | ||
return this.stream.on('error', listener); | ||
} | ||
} | ||
|
||
function zip5() { | ||
const zipStream = createWriteStream(zipPath); | ||
let wrapper = new StreamWrapper3(); | ||
wrapper.pipeIt(zipStream); // $MISSING:Alert | ||
zipStream.on('error', e); | ||
} | ||
function zip6() { | ||
const zipStream = createWriteStream(zipPath); | ||
let wrapper = new StreamWrapper3(); | ||
wrapper.pipeIt(zipStream); | ||
wrapper.register_error_handler(e); | ||
zipStream.on('error', e); | ||
} | ||
|
||
function registerErr(stream, listerner) { | ||
stream.on('error', listerner); | ||
} | ||
|
||
function zip7() { | ||
const zipStream = createWriteStream(zipPath); | ||
let stream = getStream(); | ||
registerErr(stream, e); | ||
stream.pipe(zipStream); // $SPURIOUS:Alert | ||
zipStream.on('error', e); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.