Skip to content

Conversation

jeongsoolee09
Copy link
Contributor

@jeongsoolee09 jeongsoolee09 commented Aug 26, 2025

What This PR Contributes

This PR contributes two things to the CAP log injection query: making it more resilient and more conservative.

Make the query more resilient

It is observed that the request parameter object can be tossed around interprocedurally until it is read downstream. For example:

const cds = require("@sap/cds");
const Log = cds.log("someLogger");

module.exports = class SomeService extends cds.ApplicationService {
  init() {
    this.on("SomeEvent", (req) => {
      const x = f(req);
      Log.info(x);
    }
  }
}

function f(req) { return req.data; }

The untrusted property req.data is read in a callee downstream. This code previously could not be detected since property reads are tracked only locally. Therefore, wrap the request parameter definition in a type tracker to track it inter-procedurally.

Make the query more conservative

A CDS element declared in a .cds file can lack its type information for several reasons, notably because it borrows its type interface from one of the common aspects that comes with the NPM package @sap/cds which CodeQL analysis can't get to. In this case, it makes sense to be conservative and decide that a request parameter is a barrier only if its matching type information can statically be found in its CDS declaration and it's either String or LargeString. That is, the query now conservatively decides that the request parameter data can be an injection vector if it can't be sure it's a string type, even if in fact it is not a string type.

Future Works

None at the moment.

Copy link
Contributor

@knewbury01 knewbury01 left a comment

Choose a reason for hiding this comment

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

can we add a test case that shows the interprocedural case for the req params? nice work on that though, that totally makes sense to add!

additionally there are some current unit test changes, are those expected?

jeongsoolee09 and others added 5 commits August 26, 2025 15:50
Co-authored-by: Kristen Newbury <knewbury01@github.com>
Co-authored-by: Kristen Newbury <knewbury01@github.com>
…advanced-security/codeql-sap-js into jeongsoolee09/improve-cap-log-injection
@jeongsoolee09
Copy link
Contributor Author

@knewbury01 Test cases are added in f2511a2.

Copy link
Contributor

@knewbury01 knewbury01 left a comment

Choose a reason for hiding this comment

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

lgtm!

@jeongsoolee09 jeongsoolee09 merged commit 33e30b9 into main Aug 27, 2025
5 checks passed
@jeongsoolee09 jeongsoolee09 deleted the jeongsoolee09/improve-cap-log-injection branch August 27, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants