mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
JS: Add example of bad NodeJS detection
Notice the TRAP lines ``` is_module(#20001) is_es2015_module(#20001) ```
This commit is contained in:
6
javascript/extractor/tests/node/input/detection.js
Normal file
6
javascript/extractor/tests/node/input/detection.js
Normal file
@@ -0,0 +1,6 @@
|
||||
// the comment below (with 'import' on line starting with whitespace) caused the
|
||||
// extractor to think it was a es2015 module and not a commonjs module.
|
||||
/*
|
||||
import
|
||||
*/
|
||||
const fs = require('fs');
|
||||
203
javascript/extractor/tests/node/output/trap/detection.js.trap
Normal file
203
javascript/extractor/tests/node/output/trap/detection.js.trap
Normal file
@@ -0,0 +1,203 @@
|
||||
#10000=@"/detection.js;sourcefile"
|
||||
files(#10000,"/detection.js")
|
||||
#10001=@"/;folder"
|
||||
folders(#10001,"/")
|
||||
containerparent(#10001,#10000)
|
||||
#10002=@"loc,{#10000},0,0,0,0"
|
||||
locations_default(#10002,#10000,0,0,0,0)
|
||||
hasLocation(#10000,#10002)
|
||||
#20000=@"global_scope"
|
||||
scopes(#20000,0)
|
||||
#20001=@"script;{#10000},1,1"
|
||||
#20002=*
|
||||
comments(#20002,0,#20001," the comment below (with 'import' on line starting with whitespace) caused the","// the ... sed the")
|
||||
#20003=@"loc,{#10000},1,1,1,80"
|
||||
locations_default(#20003,#10000,1,1,1,80)
|
||||
hasLocation(#20002,#20003)
|
||||
#20004=*
|
||||
comments(#20004,0,#20001," extractor to think it was a es2015 module and not a commonjs module.","// extr ... module.")
|
||||
#20005=@"loc,{#10000},2,1,2,71"
|
||||
locations_default(#20005,#10000,2,1,2,71)
|
||||
hasLocation(#20004,#20005)
|
||||
#20006=*
|
||||
comments(#20006,1,#20001,"
|
||||
import
|
||||
","/*\n import\n*/")
|
||||
#20007=@"loc,{#10000},3,1,5,2"
|
||||
locations_default(#20007,#10000,3,1,5,2)
|
||||
hasLocation(#20006,#20007)
|
||||
#20008=*
|
||||
lines(#20008,#20001,"// the comment below (with 'import' on line starting with whitespace) caused the","
|
||||
")
|
||||
hasLocation(#20008,#20003)
|
||||
#20009=*
|
||||
lines(#20009,#20001,"// extractor to think it was a es2015 module and not a commonjs module.","
|
||||
")
|
||||
hasLocation(#20009,#20005)
|
||||
#20010=*
|
||||
lines(#20010,#20001,"/*","
|
||||
")
|
||||
#20011=@"loc,{#10000},3,1,3,2"
|
||||
locations_default(#20011,#10000,3,1,3,2)
|
||||
hasLocation(#20010,#20011)
|
||||
#20012=*
|
||||
lines(#20012,#20001," import","
|
||||
")
|
||||
#20013=@"loc,{#10000},4,1,4,8"
|
||||
locations_default(#20013,#10000,4,1,4,8)
|
||||
hasLocation(#20012,#20013)
|
||||
indentation(#10000,4," ",2)
|
||||
#20014=*
|
||||
lines(#20014,#20001,"*/","
|
||||
")
|
||||
#20015=@"loc,{#10000},5,1,5,2"
|
||||
locations_default(#20015,#10000,5,1,5,2)
|
||||
hasLocation(#20014,#20015)
|
||||
#20016=*
|
||||
lines(#20016,#20001,"const fs = require('fs');","
|
||||
")
|
||||
#20017=@"loc,{#10000},6,1,6,25"
|
||||
locations_default(#20017,#10000,6,1,6,25)
|
||||
hasLocation(#20016,#20017)
|
||||
numlines(#20001,6,1,5)
|
||||
#20018=*
|
||||
tokeninfo(#20018,7,#20001,0,"const")
|
||||
#20019=@"loc,{#10000},6,1,6,5"
|
||||
locations_default(#20019,#10000,6,1,6,5)
|
||||
hasLocation(#20018,#20019)
|
||||
next_token(#20002,#20018)
|
||||
next_token(#20004,#20018)
|
||||
next_token(#20006,#20018)
|
||||
#20020=*
|
||||
tokeninfo(#20020,6,#20001,1,"fs")
|
||||
#20021=@"loc,{#10000},6,7,6,8"
|
||||
locations_default(#20021,#10000,6,7,6,8)
|
||||
hasLocation(#20020,#20021)
|
||||
#20022=*
|
||||
tokeninfo(#20022,8,#20001,2,"=")
|
||||
#20023=@"loc,{#10000},6,10,6,10"
|
||||
locations_default(#20023,#10000,6,10,6,10)
|
||||
hasLocation(#20022,#20023)
|
||||
#20024=*
|
||||
tokeninfo(#20024,6,#20001,3,"require")
|
||||
#20025=@"loc,{#10000},6,12,6,18"
|
||||
locations_default(#20025,#10000,6,12,6,18)
|
||||
hasLocation(#20024,#20025)
|
||||
#20026=*
|
||||
tokeninfo(#20026,8,#20001,4,"(")
|
||||
#20027=@"loc,{#10000},6,19,6,19"
|
||||
locations_default(#20027,#10000,6,19,6,19)
|
||||
hasLocation(#20026,#20027)
|
||||
#20028=*
|
||||
tokeninfo(#20028,4,#20001,5,"'fs'")
|
||||
#20029=@"loc,{#10000},6,20,6,23"
|
||||
locations_default(#20029,#10000,6,20,6,23)
|
||||
hasLocation(#20028,#20029)
|
||||
#20030=*
|
||||
tokeninfo(#20030,8,#20001,6,")")
|
||||
#20031=@"loc,{#10000},6,24,6,24"
|
||||
locations_default(#20031,#10000,6,24,6,24)
|
||||
hasLocation(#20030,#20031)
|
||||
#20032=*
|
||||
tokeninfo(#20032,8,#20001,7,";")
|
||||
#20033=@"loc,{#10000},6,25,6,25"
|
||||
locations_default(#20033,#10000,6,25,6,25)
|
||||
hasLocation(#20032,#20033)
|
||||
#20034=*
|
||||
tokeninfo(#20034,0,#20001,8,"")
|
||||
#20035=@"loc,{#10000},7,1,7,0"
|
||||
locations_default(#20035,#10000,7,1,7,0)
|
||||
hasLocation(#20034,#20035)
|
||||
toplevels(#20001,0)
|
||||
#20036=@"loc,{#10000},1,1,7,0"
|
||||
locations_default(#20036,#10000,1,1,7,0)
|
||||
hasLocation(#20001,#20036)
|
||||
#20037=@"var;{global};{#20000}"
|
||||
variables(#20037,"global",#20000)
|
||||
#20038=@"var;{process};{#20000}"
|
||||
variables(#20038,"process",#20000)
|
||||
#20039=@"var;{console};{#20000}"
|
||||
variables(#20039,"console",#20000)
|
||||
#20040=@"var;{Buffer};{#20000}"
|
||||
variables(#20040,"Buffer",#20000)
|
||||
#20041=@"module;{#10000},1,1"
|
||||
scopes(#20041,3)
|
||||
scopenodes(#20001,#20041)
|
||||
scopenesting(#20041,#20000)
|
||||
#20042=@"var;{require};{#20041}"
|
||||
variables(#20042,"require",#20041)
|
||||
#20043=@"var;{module};{#20041}"
|
||||
variables(#20043,"module",#20041)
|
||||
#20044=@"var;{exports};{#20041}"
|
||||
variables(#20044,"exports",#20041)
|
||||
#20045=@"var;{__filename};{#20041}"
|
||||
variables(#20045,"__filename",#20041)
|
||||
#20046=@"var;{__dirname};{#20041}"
|
||||
variables(#20046,"__dirname",#20041)
|
||||
#20047=@"var;{arguments};{#20041}"
|
||||
variables(#20047,"arguments",#20041)
|
||||
is_module(#20001)
|
||||
is_es2015_module(#20001)
|
||||
#20048=@"var;{fs};{#20041}"
|
||||
variables(#20048,"fs",#20041)
|
||||
#20049=*
|
||||
stmts(#20049,22,#20001,0,"const f ... ('fs');")
|
||||
hasLocation(#20049,#20017)
|
||||
stmt_containers(#20049,#20001)
|
||||
#20050=*
|
||||
exprs(#20050,64,#20049,0,"fs = require('fs')")
|
||||
#20051=@"loc,{#10000},6,7,6,24"
|
||||
locations_default(#20051,#10000,6,7,6,24)
|
||||
hasLocation(#20050,#20051)
|
||||
enclosing_stmt(#20050,#20049)
|
||||
expr_containers(#20050,#20001)
|
||||
#20052=*
|
||||
exprs(#20052,78,#20050,0,"fs")
|
||||
hasLocation(#20052,#20021)
|
||||
enclosing_stmt(#20052,#20049)
|
||||
expr_containers(#20052,#20001)
|
||||
literals("fs","fs",#20052)
|
||||
decl(#20052,#20048)
|
||||
#20053=*
|
||||
exprs(#20053,13,#20050,1,"require('fs')")
|
||||
#20054=@"loc,{#10000},6,12,6,24"
|
||||
locations_default(#20054,#10000,6,12,6,24)
|
||||
hasLocation(#20053,#20054)
|
||||
enclosing_stmt(#20053,#20049)
|
||||
expr_containers(#20053,#20001)
|
||||
#20055=*
|
||||
exprs(#20055,79,#20053,-1,"require")
|
||||
hasLocation(#20055,#20025)
|
||||
enclosing_stmt(#20055,#20049)
|
||||
expr_containers(#20055,#20001)
|
||||
literals("require","require",#20055)
|
||||
bind(#20055,#20042)
|
||||
#20056=*
|
||||
exprs(#20056,4,#20053,0,"'fs'")
|
||||
hasLocation(#20056,#20029)
|
||||
enclosing_stmt(#20056,#20049)
|
||||
expr_containers(#20056,#20001)
|
||||
literals("fs","'fs'",#20056)
|
||||
#20057=*
|
||||
regexpterm(#20057,14,#20056,0,"fs")
|
||||
#20058=@"loc,{#10000},6,21,6,22"
|
||||
locations_default(#20058,#10000,6,21,6,22)
|
||||
hasLocation(#20057,#20058)
|
||||
regexp_const_value(#20057,"fs")
|
||||
#20059=*
|
||||
entry_cfg_node(#20059,#20001)
|
||||
#20060=@"loc,{#10000},1,1,1,0"
|
||||
locations_default(#20060,#10000,1,1,1,0)
|
||||
hasLocation(#20059,#20060)
|
||||
#20061=*
|
||||
exit_cfg_node(#20061,#20001)
|
||||
hasLocation(#20061,#20035)
|
||||
successor(#20049,#20052)
|
||||
successor(#20056,#20053)
|
||||
successor(#20055,#20056)
|
||||
successor(#20053,#20050)
|
||||
successor(#20052,#20055)
|
||||
successor(#20050,#20061)
|
||||
successor(#20059,#20049)
|
||||
numlines(#10000,6,1,5)
|
||||
filetype(#10000,"javascript")
|
||||
Reference in New Issue
Block a user