Skip to content

Conversation

knewbury01
Copy link
Contributor

What This PR Contributes

  • A path injection/traversal query PathInjection.ql
  • Unit tests for the query
  • A patch to the prior model of CDS utils taint steps for a mistake in the modelling of args/calls as in/out nodes

Future Works

Add additional unit tests if the extra API cases described here in the future works are covered in the future.

@knewbury01 knewbury01 changed the title Add path injection query and patch path injection taint model Add CDS Utils path injection query Aug 21, 2025

const taint5 = isfile(userinputthree) // taint step

const pkg = await read(taint1) // sink

Check failure

Code scanning / CodeQL

Use of user controlled input in CAP CDS file system utilies High test

This CDS utils usage relies on user-provided value and can result in unrestricted file operations.

const pkg = await read(taint1) // sink

const pdir = await readdir(taint2) // sink

Check failure

Code scanning / CodeQL

Use of user controlled input in CAP CDS file system utilies High test

This CDS utils usage relies on user-provided value and can result in unrestricted file operations.

const pdir = await readdir(taint2) // sink

const s = await stat(taint3) // sink

Check failure

Code scanning / CodeQL

Use of user controlled input in CAP CDS file system utilies High test

This CDS utils usage relies on user-provided value and can result in unrestricted file operations.

const s = await stat(taint3) // sink

const f = await find(taint4) // sink

Check failure

Code scanning / CodeQL

Use of user controlled input in CAP CDS file system utilies High test

This CDS utils usage relies on user-provided value and can result in unrestricted file operations.

const f = await find(taint4) // sink

await append('db/data').to(taint5) // sink

Check failure

Code scanning / CodeQL

Use of user controlled input in CAP CDS file system utilies High test

This CDS utils usage relies on user-provided value and can result in unrestricted file operations.
await mkdirp(userinput) // sink

await rmdir(userinput, 'db', 'data') // sink
await rmdir(userinput) // sink

Check failure

Code scanning / CodeQL

Use of user controlled input in CAP CDS file system utilies High test

This CDS utils usage relies on user-provided value and can result in unrestricted file operations.
await rmdir(userinput, 'db', 'data') // sink
await rmdir(userinput) // sink

await rimraf(userinput, 'db', 'data') // sink

Check failure

Code scanning / CodeQL

Use of user controlled input in CAP CDS file system utilies High test

This CDS utils usage relies on user-provided value and can result in unrestricted file operations.
await rmdir(userinput) // sink

await rimraf(userinput, 'db', 'data') // sink
await rimraf(userinput) // sink

Check failure

Code scanning / CodeQL

Use of user controlled input in CAP CDS file system utilies High test

This CDS utils usage relies on user-provided value and can result in unrestricted file operations.
await rimraf(userinput, 'db', 'data') // sink
await rimraf(userinput) // sink

await rm(userinput, 'db', 'data') // sink

Check failure

Code scanning / CodeQL

Use of user controlled input in CAP CDS file system utilies High test

This CDS utils usage relies on user-provided value and can result in unrestricted file operations.
await rimraf(userinput) // sink

await rm(userinput, 'db', 'data') // sink
await rm(userinput) // sink

Check failure

Code scanning / CodeQL

Use of user controlled input in CAP CDS file system utilies High test

This CDS utils usage relies on user-provided value and can result in unrestricted file operations.
Copy link
Contributor

@jeongsoolee09 jeongsoolee09 left a comment

Choose a reason for hiding this comment

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

Nice work. I'd like to suggest two things:

Lack of barriers

A barrier is lacking in this example. Research some well-known ways to neutralize path traversal and ones that are specific to CAP, and add both to the Recommendations section of the help file and to the isBarrier predicate of the configuration.

CDSAdditionalFlowStep hard to understand at first glance

It's a bit hard to follow the logic of CDSAdditionalFlowStep, and much of it is coming from the fact that conceptually a flow step is a pair of two dataflow nodes but the implementation at the moment is a DataFlow::Node.

But admittedly encoding a tuple can be a bit verbose to model in QL. So I think it's better to remove the hierarchy only for additional flow steps and directly inline the class definition into the isAdditionalStep predicate. It seems like the default queries are following this practice.

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