Skip to content

Conversation

jeongsoolee09
Copy link
Contributor

@jeongsoolee09 jeongsoolee09 commented Jul 29, 2025

What This PR Contributes

Refine the definition of the remote flow source of CAP

This PR refines the remote flow source of CAP by restricting the definition to reads of property on the program elements previously detected as remote flow sources, namely, parameters of handlers belonging to a service that is exposed to a web protocol. This PR achieves it through the following changes:

  1. Stop making HandlerParameterOfExposedService extend RemoteFlowSource, and
  2. Create UserProvidedPropertyReadOfHandlerParameterOfExposedService and make it extend that instead.

Enhance unit tests in remoteflowsources

Tidy up the test project

The test project had several rooms of improvement:

  1. The file names that held user-defined application services did not match their name. This made it a bit disorienting to the reader of the test case.
  2. The cds.serve(...).with(...) calls are typically stored in a main entrypoint, so move it there (even if it's technically allowed to be place anywhere).

Make another model test query

Also, this PR adds another complementary unit test, ExposedServices that tests the class HandlerParameterOfExposedService, now demoted from being a remote flow source. It is still an important class so we would want to still test if it is working properly.

Running the test locally

First, compile the .cds files by running the script extractors/cds/tools/workflow/cds-compilation-for-actions.sh. Then, run export LGTM_INDEX_FILTERS=include:**/*.json to enable JSON extraction for your shell session. You should be prepared to create the database with codeql database create --language=javascript.

Future Works

  1. There is another unit test requesthandler, and what it intends to test is already covered in this unit test. So, it can be safely deleted.
  2. I noticed that cds.serve(...) can also accept a path string relative to the entrypoint of the root of the application, but it is not yet modeled. Modeling it can be a future work.

- `service3nocds.js` had a service that was named differently. Clarified the gist of the file using tags.
- `service4.js` was identical to `service3nocds.js`, except for the `cds.serve` call. This is better suited for `server.js`.
- Since `HandlerParameterOfExposedService` is no longer a `RemoteFlowSource`, we place another query for testing it only.
- The case categorization is as follows:
  - `service1`: Exposed service with reads from properties and method calls, some of which are tainted and not tainted.
  - `service2`: Service that both receives data from service1 and service4 but does not propagate it further.
  - `service3`: Service without a CDS declaration, simulating extraction failure. Should be recognized as exposed, from overapproximation. Consists of identical property reads / method calls as those of `service1`.
  - `service4`: Service that is explicitly declared as internal only. Consists of identical property reads / method calls as those of `service1`, but is not a taint source from being unexposed.
The locations changed a little from altering the definition of
`RemoteFlowSource` to the property reads of the parameter, not
the parameter itself.
- `server.js` had a reference to a service that doesn't exist. Made it point to Service1 instead.
- Create expected results of `ExposedServices`, a complementary test to `RemoteFlowSource`.
@jeongsoolee09 jeongsoolee09 marked this pull request as ready for review August 4, 2025 16:50
The results from query predicates changed a little from altering
the definition of `RemoteFlowSource` to the property reads of the
parameter, not the parameter itself.
Copy link
Collaborator

@data-douser data-douser left a comment

Choose a reason for hiding this comment

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

One minor question about an expected result.

@jeongsoolee09 jeongsoolee09 self-assigned this Aug 5, 2025
Add a `cds.serve(...).with(...)` that expands the
functionality of Service3 which lacks a CDS declaration.

Since Service3 is missing a CDS declaration, all of the
handlers registrated in the `.with` method call should
be considered as exposed.
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! nice work, thanks!

@jeongsoolee09 jeongsoolee09 merged commit 8918839 into main Aug 7, 2025
5 checks passed
@jeongsoolee09 jeongsoolee09 deleted the jeongsoolee09/restrict-cap-remoteflowsource-properties branch August 7, 2025 19:40
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.

3 participants