File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed
javascript/frameworks/cap
test/queries/path-traversal Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,14 @@ module.exports = class Service1 extends cds.ApplicationService {
3838 this .on (" send1" , async (req ) => {
3939 let userinput = req .data
4040 await write (userinput).to (' db/data' ) // Path injection alert
41+
42+ // GOOD: the path can not be controlled by an attacker
43+ let allowedDirectories = [
44+ ' this-is-a-safe-directory'
45+ ];
46+ if (allowedDirectories .includes (userinput)) {
47+ await rm (userinput) // sanitized - No Path injection alert
48+ }
4149 }
4250 }
4351}
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import javascript
1717import advanced_security.javascript.frameworks.cap.CAPPathInjectionQuery
1818import advanced_security.javascript.frameworks.cap.RemoteFlowSources
1919private import semmle.javascript.security.dataflow.TaintedPathCustomizations
20- private import semmle.javascript.security.dataflow.TaintedPathQuery
20+ private import semmle.javascript.security.dataflow.TaintedPathQuery as tq
2121
2222module PathInjectionConfig implements DataFlow:: ConfigSig {
2323 predicate isSource ( DataFlow:: Node node ) { node instanceof RemoteFlowSource }
@@ -33,7 +33,7 @@ module PathInjectionConfig implements DataFlow::ConfigSig {
3333 predicate isBarrier ( DataFlow:: Node node ) {
3434 node instanceof TaintedPath:: Sanitizer
3535 or
36- TaintedPathConfig:: isBarrier ( node )
36+ tq :: TaintedPathConfig:: isBarrier ( node )
3737 }
3838}
3939
Original file line number Diff line number Diff line change @@ -48,6 +48,13 @@ module.exports = class Service1 extends cds.ApplicationService {
4848
4949 await rm ( userinput , 'db' , 'data' ) // sink
5050 await rm ( userinput ) // sink
51+
52+ let allowedDirectories = [
53+ 'this-is-a-safe-directory'
54+ ] ;
55+ if ( allowedDirectories . includes ( userinput ) ) {
56+ await rm ( userinput ) // sanitized
57+ }
5158 } ) ;
5259
5360 super . init ( ) ;
You can’t perform that action at this time.
0 commit comments