Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,26 @@ class HandlerParameter extends ParameterNode, RemoteFlowSource {
result = "Parameter of an event handler belonging to an exposed service"
}
}

/**
* A service may be described only in a CDS file, but event handlers may still be registered in a format such as:
* ```javascript
* module.exports = srv => {
* srv.before('CREATE', 'Media', req => { //service name is used to describe which to register this handler to
* ```
* parameters named `req` are captured in the above example.
*/
class ServiceinCDSHandlerParameter extends RemoteFlowSource {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this make use HandlerRegistration in CDS.qll ? Or is this exactly what you wanted to avoid?

Copy link
Contributor Author

@knewbury01 knewbury01 Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically that part could work, but yeah,
then we would still need to modify the definition of UserDefinedApplicationService which only describes js defined extensions of extends cds.ApplicationService, which I was thinking was cleaner/fits nicer into the overall model, but maybe isnt worth the extra (not undoable but more involved) refactoring

ServiceinCDSHandlerParameter() {
exists(MethodCallNode m, CdlEntity service, string serviceName |
service.getName().regexpReplaceAll(".*\\.", "") = serviceName and
m.getArgument(1).toString().regexpReplaceAll("'", "") = serviceName and
this = m.getArgument(2) and
m.getMethodName() in ["on", "before", "after"]
)
}

override string getSourceType() {
result = "Parameter of an event handler belonging to an exposed service defined in a cds file"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace sap.capire.test;

entity Test {

key id:Integer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| remoteflowsource.js:6:34:9:5 | req => ... i\\n } |
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const loki = require('lokijs')
const db = new loki('DB')
const testDB = db.addCollection('Test')

module.exports = srv => {
srv.before('CREATE', 'Test', req => { //source
const obj = testDB.insert({ test: '' })
req.data.id = obj.$loki
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import javascript
import advanced_security.javascript.frameworks.cap.RemoteFlowSources

from RemoteFlowSource source
select source
8 changes: 8 additions & 0 deletions scripts/create-db-with-cds.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/bash
# !!!!!!! Run it at javascript/frameworks/cap/test/queries/test/queries/ !!!!!!!

#test if codeql is on the path
if command -v codeql
then

# Remember current directory
TEST_DIR=$(pwd)

Expand Down Expand Up @@ -35,3 +39,7 @@ for dir in *; do
done

echo "Done!"

else
echo "Add CodeQL to PATH!"
fi
8 changes: 8 additions & 0 deletions scripts/create-db.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/bash
# !!!!!!! Run it at javascript/frameworks/ui5/test/queries/test/queries/ !!!!!!!

#test if codeql is on the path
if command -v codeql
then

# Remember current directory
TEST_DIR=$(pwd)

Expand All @@ -26,3 +30,7 @@ for dir in *; do
done

echo "Done!"

else
echo "Add CodeQL to PATH!"
fi