Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
5a52340
Add draft of multi-service, message-passing log poc
jeongsoolee09 Feb 13, 2024
bb8fe73
Finalize draft on log injection app
jeongsoolee09 Feb 13, 2024
1e69a23
Remove unnecessary devDependencies in package.json
jeongsoolee09 Feb 13, 2024
c71ef16
Wrong entity name
jeongsoolee09 Feb 13, 2024
810942e
Add draft of SQL injection PoC
jeongsoolee09 Feb 13, 2024
140cee0
Fix CQL expression to be vulnerable to SQL injection
jeongsoolee09 Feb 13, 2024
f354b9d
Add missing `init()` and add some comments
jeongsoolee09 Feb 14, 2024
3f50833
Normalize import path and remove redundant module declaration
jeongsoolee09 Feb 14, 2024
7d2a95f
Introduce variant `ImplMethodCall`
jeongsoolee09 Feb 14, 2024
f8588fb
Add missing await on call to `cds.connect.to`
jeongsoolee09 Feb 14, 2024
a097e04
Add classes predicates
jeongsoolee09 Feb 14, 2024
7a97eb0
Add CDL.qll
jeongsoolee09 Feb 15, 2024
db58714
Fix parsing errors on the cds files
jeongsoolee09 Feb 15, 2024
5bc2a79
Implement and clean up definitions of `Handler`s
jeongsoolee09 Feb 15, 2024
9035377
Fix failing unit tests
jeongsoolee09 Feb 16, 2024
7b28623
Add and reorder classes
jeongsoolee09 Feb 16, 2024
cb2c7b6
Rename ApplicationService to CdsApplicationService
jeongsoolee09 Feb 16, 2024
a95b38d
Fix unit test `requesthandler`
jeongsoolee09 Feb 17, 2024
4d82d20
Fix unit test
jeongsoolee09 Feb 17, 2024
b816eaf
Fix `applicationserviceinstance` unit test
jeongsoolee09 Feb 17, 2024
914e825
Create CAPLogInjection class to accommodate related classes
jeongsoolee09 Feb 17, 2024
a4c0d20
Fix `logger` unit test
jeongsoolee09 Feb 17, 2024
624a91d
Fix `loginjection`/`sqlinjection` unit tests
jeongsoolee09 Feb 20, 2024
286980b
Rename app to something specific
jeongsoolee09 Feb 21, 2024
f747d22
Move existing loginjection.js to a separate directory
jeongsoolee09 Feb 21, 2024
765608d
Add three more variants of `log-injection-with-partial-protocol-none`
jeongsoolee09 Feb 21, 2024
67357f6
Add description to each README and add missing annotation
jeongsoolee09 Feb 22, 2024
69c1bf7
Create `dataflow/` and move `ParseSink` there
jeongsoolee09 Feb 22, 2024
1e63e5d
Add `PackageJson.qll`
jeongsoolee09 Feb 23, 2024
19912c8
Add more classes
jeongsoolee09 Feb 23, 2024
3181a5d
Add more classes and predicates
jeongsoolee09 Feb 24, 2024
34be530
Debug `log-injection-with-partial-protocol-none`
jeongsoolee09 Feb 24, 2024
78b29a2
Add `AsyncStyleCommunication` in `DataFlow.qll`
jeongsoolee09 Feb 24, 2024
c01f19e
Update all log injection test cases
jeongsoolee09 Feb 28, 2024
fabd8c4
Rename existing test case and add new one
jeongsoolee09 Feb 28, 2024
a70d59a
Update script to only run locally and not on Codespaces
jeongsoolee09 Feb 29, 2024
4692365
Change UserDefinedApplicationService to abstract class
jeongsoolee09 Feb 29, 2024
f7846a2
Remove `@protocol: 'none'` in Service1.cds
jeongsoolee09 Mar 1, 2024
818a394
Minor formatting
jeongsoolee09 Mar 1, 2024
3489055
Recompile modified CDS files
jeongsoolee09 Mar 1, 2024
efd09b3
Implement `getHandlerRegistration/1`
jeongsoolee09 Mar 2, 2024
3d80c3b
Add transitive import of FlowSteps
jeongsoolee09 Mar 2, 2024
3b1ec26
Add more fields and getters to `InterServiceCommunication`
jeongsoolee09 Mar 2, 2024
e6e6991
Debug `InterServiceCommunicationStepFromSenderToReceiver`
jeongsoolee09 Mar 2, 2024
14c4807
Minor stylistic change
jeongsoolee09 Mar 2, 2024
a3b8373
Finish first draft of multi-service log injection
jeongsoolee09 Mar 5, 2024
f342004
Debug query for log-injection-with-service2-protocol-none
jeongsoolee09 Mar 5, 2024
c5ecf1e
Add separate script to build database with (compiled) cds files
jeongsoolee09 Mar 6, 2024
f61be3d
Change bit of comment in create-db.sh
jeongsoolee09 Mar 6, 2024
bef79db
Update unit test cases and .expected files
jeongsoolee09 Mar 6, 2024
91c8358
Fix all unit tests
jeongsoolee09 Mar 6, 2024
4cdbcff
Merge branch 'main' of github.com:advanced-security/codeql-sap-js int…
jeongsoolee09 Mar 6, 2024
2be5dab
Fix log-injection-single-file
jeongsoolee09 Mar 7, 2024
37eeac3
Fix `userdefinedservice` test
jeongsoolee09 Mar 7, 2024
cd9bbe7
Fix `requesthandler` unit test
jeongsoolee09 Mar 7, 2024
62b5c91
Fix failing unit tests due to compilation error
jeongsoolee09 Mar 7, 2024
b57a7c6
Fix `applicationserviceinstance` test
jeongsoolee09 Mar 7, 2024
f211169
Update untracked json files compiled from cds files
jeongsoolee09 Mar 8, 2024
3ab3c72
Check diagram svgs into repository
jeongsoolee09 Mar 13, 2024
ecdb36f
Add inline comment to signal CAP/vanilla log injection sinks
jeongsoolee09 Mar 19, 2024
eb5b49e
Fix `log-injection-not-depending-on-request`
jeongsoolee09 Mar 20, 2024
06b685f
Restrict search space to the same application
jeongsoolee09 Mar 20, 2024
3f668c3
Untrack `.json` files compiled from `.cds` files
jeongsoolee09 Mar 20, 2024
a3f5099
Untrack `.json` files compiled from `.cds` files
jeongsoolee09 Mar 20, 2024
054be51
Update `javascript.sarif.expected`
jeongsoolee09 Mar 20, 2024
b166ee1
Untrack `.json` files compiled from `.cds` files
jeongsoolee09 Mar 20, 2024
f86e613
Recognize accompanying .cds files as ".cds.json"
jeongsoolee09 Mar 20, 2024
7518e3a
Update the script to compile `.cds` files
jeongsoolee09 Mar 20, 2024
d393a1d
Update workflow files to ensure presence of `cds` shell command
jeongsoolee09 Mar 21, 2024
abc1942
Debug `Compile CAP CDS files` step
jeongsoolee09 Mar 21, 2024
79fab0d
Remove `npm install` command from both workflows
jeongsoolee09 Mar 21, 2024
c4bc859
Update code_scanning.yml
jeongsoolee09 Mar 21, 2024
a98747e
Update run-codeql-unit-tests-javascript.yml
jeongsoolee09 Mar 21, 2024
8875027
Merge branch 'main' into jeongsoolee09/cover-multi-service-log-i
jeongsoolee09 Mar 25, 2024
e9df248
Update sqlinjection to appease batch CDS compilation
jeongsoolee09 Mar 25, 2024
8278b9f
Merge branch 'jeongsoolee09/cover-multi-service-log-i' of github.com:…
jeongsoolee09 Mar 25, 2024
24748e5
Fix `using` path
jeongsoolee09 Mar 25, 2024
69e4590
Add a debug echo in the workflows
jeongsoolee09 Mar 25, 2024
c9219f7
Add debug echo
jeongsoolee09 Mar 25, 2024
60e3550
Rename files
jeongsoolee09 Mar 25, 2024
cb9a9f6
Rename files
jeongsoolee09 Mar 25, 2024
ad38212
Delete cqlinjection and sqlinjection
jeongsoolee09 Mar 25, 2024
3406c27
update javascript.sarif.expected
jeongsoolee09 Mar 25, 2024
3aefa19
Revert "update javascript.sarif.expected"
jeongsoolee09 Mar 25, 2024
59a3f6c
Update run-codeql-unit-tests-javascript.yml
jeongsoolee09 Mar 25, 2024
118c3b6
Testing by shuffling around the steps a bit
jeongsoolee09 Mar 25, 2024
9ed78dd
Merge branch 'jeongsoolee09/cover-multi-service-log-i' of github.com:…
jeongsoolee09 Mar 25, 2024
c9ce5a8
Revert "Perform missing version ups from 0.5.0 to 0.6.0"
jeongsoolee09 Mar 26, 2024
93704f7
fix paths for json files compiled from cds
mbaluda Mar 26, 2024
66a067c
Add back `cqlinjection`
jeongsoolee09 Mar 26, 2024
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
35 changes: 27 additions & 8 deletions .github/workflows/code_scanning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ on:
branches: [ "main" ]
schedule:
- cron: '39 12 * * 2'

workflow_dispatch:

env:
LGTM_INDEX_XML_MODE: all
LGTM_INDEX_FILTERS: "include:**/*.json"

jobs:
analyze:
Expand All @@ -35,6 +37,24 @@ jobs:
mv $dir .github/codeql/extensions/$dir
done

- name: Ensure presence of cds shell command
run: |
if ! command -v cds &> /dev/null
then
npm install -g @sap/cds-dk
fi

# Compile .cds files to .cds.json files.
- name: Compile CAP CDS files
run: |
for cds_file in $(find . -type f \( -iname '*.cds' \) -print)
do
echo "I am compiling $cds_file"
cds compile $cds_file \
-2 json \
-o "$cds_file.json"
done

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand All @@ -46,17 +66,17 @@ jobs:
- name: Perform CodeQL Analysis
id: analyze
uses: github/codeql-action/analyze@v3

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.10'

- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip

- name: Validate results
continue-on-error: true
id: validate
Expand All @@ -66,7 +86,7 @@ jobs:
sarif diff ${{ steps.analyze.outputs.sarif-output }} .github/workflows/javascript.sarif.expected -o sarif-diff.json
cat sarif-diff.json
! grep -q "[1-9]" sarif-diff.json

- name: Upload sarif change
if: steps.validate.outcome != 'success'
uses: actions/upload-artifact@v4
Expand All @@ -75,10 +95,9 @@ jobs:
path: |
sarif-diff.json
${{ steps.analyze.outputs.sarif-output }}

- name: Unexpected Code Scanning results
if: steps.validate.outcome != 'success'
run: |
cat sarif-diff.json
echo "::error::Unexpected Code Scanning results!" && exit 1

13,574 changes: 7,897 additions & 5,677 deletions .github/workflows/javascript.sarif.expected

Large diffs are not rendered by default.

41 changes: 30 additions & 11 deletions .github/workflows/run-codeql-unit-tests-javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
with:
qlt-version: 'latest'
add-to-path: true

- name: Install CodeQL
id: install-codeql
shell: bash
Expand All @@ -61,13 +61,13 @@ jobs:
echo "-----------------------------"
echo "CodeQL Home: $QLT_CODEQL_HOME"
echo "CodeQL Binary: $QLT_CODEQL_PATH"

- name: Verify Versions of Tooling
shell: bash
run: |
echo -e "Checking CodeQL Version:"
$QLT_CODEQL_PATH --version

echo -e "Checking QLT Version:"
echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}"
qlt version
Expand All @@ -77,6 +77,24 @@ jobs:
run: |
qlt query run install-packs

- name: Ensure presence of cds shell command
run: |
if ! command -v cds &> /dev/null
then
npm install -g @sap/cds-dk
fi

# Compile .cds files to .cds.json files.
- name: Compile CAP CDS files
run: |
for cds_file in $(find . -type f \( -iname '*.cds' \) -print)
do
echo "I am compiling $cds_file"
cds compile $cds_file \
-2 json \
-o "$cds_file.json"
done

- name: Run test suites
id: run-test-suites
env:
Expand All @@ -86,16 +104,17 @@ jobs:
CODEQL_STDLIB_IDENT: ${{matrix.codeql_standard_library_ident}}
RUNNER_TMP: ${{ runner.temp }}
LGTM_INDEX_XML_MODE: all
LGTM_INDEX_FILTERS: "include:**/*.json"

shell: bash
run: >
qlt test run execute-unit-tests
qlt test run execute-unit-tests
--codeql-args "--threads=0 --strict-test-discovery"
--num-threads 2
--language javascript
--runner-os $RUNNER_OS
--num-threads 2
--language javascript
--runner-os $RUNNER_OS
--work-dir $RUNNER_TMP

- name: Upload test results
uses: actions/upload-artifact@v2
with:
Expand All @@ -119,12 +138,12 @@ jobs:
with:
qlt-version: 'latest'
add-to-path: true


- name: Collect test results
uses: actions/download-artifact@v2

- name: Validate test results
run: |
run: |
qlt test run validate-unit-tests --pretty-print --results-directory . >> $GITHUB_STEP_SUMMARY
qlt test run validate-unit-tests --results-directory .
qlt test run validate-unit-tests --results-directory .
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Definitions pertaining to the application as a whole.
*/

import javascript
import advanced_security.javascript.frameworks.cap.PackageJson

class RootDirectory extends Folder {
RootDirectory() {
exists(PackageJson packageJson | this = packageJson.getJsonFile().getParentContainer())
}

/**
* Gets the path of a file relative to this root directory.
*/
string getFilePathRelativeToRoot(File file) {
result = file.getAbsolutePath().regexpReplaceAll(this.getAbsolutePath(), ".") and
result.charAt(0) = "."
}

/**
* Holds if this root directory of the application contains the given file.
*/
predicate contains(File file) { exists(this.getFilePathRelativeToRoot(file)) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import javascript
import semmle.javascript.dataflow.DataFlow
import semmle.javascript.security.dataflow.LogInjectionQuery
import advanced_security.javascript.frameworks.cap.RemoteFlowSources
import advanced_security.javascript.frameworks.cap.CDS
import advanced_security.javascript.frameworks.cap.dataflow.DataFlow

/**
* A logger obtained by a call to `log` on a CDS facade. Each logger is associated with
* its unique name.
*/
class CdsLogger extends MethodCallNode {
string name;

CdsLogger() {
exists(CdsFacade cds |
this = cds.getMember("log").getACall() and
name = this.getArgument(0).getALocalSource().asExpr().(StringLiteral).getValue()
)
}

string getName() { result = name }
}

/**
* Arguments of calls to `cds.log.{trace, debug, info, log, warn, error}`
*/
class CdsLogSink extends DataFlow::Node {
CdsLogSink() {
exists(CdsLogger log, MethodCallNode loggingMethod |
this = loggingMethod.getAnArgument() and
loggingMethod.getMethodName() = ["trace", "debug", "info", "log", "warn", "error"] and
not this.asExpr() instanceof Literal and
not this.asExpr() instanceof TemplateLiteral and
loggingMethod.getReceiver().getALocalSource() = log
)
}
}

class CAPLogInjectionConfiguration extends LogInjectionConfiguration {
override predicate isSource(DataFlow::Node start) {
super.isSource(start) or
start instanceof RemoteFlowSource
}

override predicate isSink(DataFlow::Node end) { end instanceof CdsLogSink }
}
Loading