Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mono-repo filtering example using a workflow matrix #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
83 changes: 83 additions & 0 deletions .github/workflows/codeql_mono.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: "CodeQL Analysis"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
workflow_dispatch:

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
include:
- language: 'java'
build-command: 'mvn compile -B'
directory: 'project1'
- language: 'java'
build-command: 'mvn compile -B'
directory: 'project2'
- language: 'java'
build-command: 'mvn compile -B'
directory: 'project3'
- language: 'java'
build-command: 'mvn compile -B'
directory: 'project4'
- language: 'javascript'
build-command: ${{ null }}
directory: 'project5'
config: |
paths:
- project5
- language: 'javascript'
build-command: ${{ null }}
directory: 'project6'
config: |
paths:
- project6

steps:
- name: Checkout repository
uses: actions/checkout@v3
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you bump that to v4 please?

nicolaswill marked this conversation as resolved.
Show resolved Hide resolved

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
queries: security-extended,security-and-quality
config: ${{ matrix.config }}

- name: Run build command for subproject
run: ${{ matrix.build-command }}
working-directory: ${{ matrix.directory }}
if: ${{ matrix.build-command }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
upload: False
output: sarif-results
env:
CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"analyze":["--sarif-add-snippets","--sarif-add-query-help","--sarif-group-rules-by-pack"]}}'

- name: Rename CodeQL tool
run: |
jq ".runs[0].tool.driver.name = \"CodeQL-${WORKFLOW_TAG}-${{matrix.language}}\"" sarif-results/${{ matrix.language }}.sarif > sarif-results/${{ matrix.language }}-edited.sarif
env:
WORKFLOW_TAG: ${{ matrix.directory }}

- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: sarif-results/${{ matrix.language }}-edited.sarif
50 changes: 50 additions & 0 deletions project5/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var fs = require('fs'),
http = require('http'),
url = require('url');

var server = http.createServer(function(req, res) {
let path = url.parse(req.url, true).query.path;

fs.readFileSync(path); // NOT OK

Check failure

Code scanning / CodeQL-project5-javascript

Uncontrolled data used in path expression High test

This path depends on a
user-provided value
.

var obj = bla ? something() : path;

fs.readFileSync(obj.sub); // NOT OK

Check failure

Code scanning / CodeQL-project5-javascript

Uncontrolled data used in path expression High test

This path depends on a
user-provided value
.

obj.sub = "safe";

fs.readFileSync(obj.sub); // OK

obj.sub2 = "safe";
if (random()) {
fs.readFileSync(obj.sub2); // OK
}

if (random()) {
obj.sub3 = "safe"

Check notice

Code scanning / CodeQL-project5-javascript

Semicolon insertion Note test

Avoid automated semicolon insertion (90% of all statements in
the enclosing function
have an explicit semicolon).

Check notice

Code scanning / CodeQL-project5-javascript

Semicolon insertion

Avoid automated semicolon insertion (90% of all statements in [the enclosing function](1) have an explicit semicolon).
}
fs.readFileSync(obj.sub3); // NOT OK

Check failure

Code scanning / CodeQL-project5-javascript

Uncontrolled data used in path expression High test

This path depends on a
user-provided value
.

obj.sub4 =
fs.readFileSync(obj.sub4) ? // NOT OK

Check failure

Code scanning / CodeQL-project5-javascript

Uncontrolled data used in path expression High test

This path depends on a
user-provided value
.
fs.readFileSync(obj.sub4) : // NOT OK

Check failure

Code scanning / CodeQL-project5-javascript

Uncontrolled data used in path expression High test

This path depends on a
user-provided value
.
fs.readFileSync(obj.sub4); // NOT OK

Check failure

Code scanning / CodeQL-project5-javascript

Uncontrolled data used in path expression High test

This path depends on a
user-provided value
.
});

server.listen();

var nodefs = require('node:fs');

var server2 = http.createServer(function(req, res) {
let path = url.parse(req.url, true).query.path;
nodefs.readFileSync(path); // NOT OK

Check failure

Code scanning / CodeQL-project5-javascript

Uncontrolled data used in path expression High test

This path depends on a
user-provided value
.

Check failure

Code scanning / CodeQL-project5-javascript

Uncontrolled data used in path expression

This path depends on a [user-provided value](1).
});

server2.listen();

const chownr = require("chownr");

var server3 = http.createServer(function (req, res) {

Check notice

Code scanning / CodeQL-project5-javascript

Unused variable, import, function or class Note test

Unused variable server3.

Check notice

Code scanning / CodeQL-project5-javascript

Unused variable, import, function or class

Unused variable server3.
let path = url.parse(req.url, true).query.path;
chownr(path, "someuid", "somegid", function (err) {}); // NOT OK

Check failure

Code scanning / CodeQL-project5-javascript

Uncontrolled data used in path expression High test

This path depends on a
user-provided value
.

Check failure

Code scanning / CodeQL-project5-javascript

Uncontrolled data used in path expression

This path depends on a [user-provided value](1).
});
18 changes: 18 additions & 0 deletions project6/UnsafeDynamicMethodAccess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// copied from tests for `UnsafeDynamicMethodAccess.ql` to check that they do not overlap

let obj = {};

window.addEventListener('message', (ev) => {

Check warning

Code scanning / CodeQL-project6-javascript

Missing origin verification in `postMessage` handler Medium

Postmessage handler has no origin check.

Check warning

Code scanning / CodeQL-project6-javascript

Missing origin verification in `postMessage` handler

Postmessage handler has no origin check.
let message = JSON.parse(ev.data);
window[message.name](message.payload); // NOT OK, but reported by UnsafeDynamicMethodAccess.ql [INCONSISTENCY]

Check failure

Code scanning / CodeQL-project6-javascript

Unsafe dynamic method access Critical

This method is invoked using a
user-controlled value
, which may allow remote code execution.

Check failure

Code scanning / CodeQL-project6-javascript

Unsafe dynamic method access

This method is invoked using a [user-controlled value](1), which may allow remote code execution.
new window[message.name](message.payload); // NOT OK, but reported by UnsafeDynamicMethodAccess.ql [INCONSISTENCY]

Check failure

Code scanning / CodeQL-project6-javascript

Unsafe dynamic method access Critical

This method is invoked using a
user-controlled value
, which may allow remote code execution.

Check failure

Code scanning / CodeQL-project6-javascript

Unsafe dynamic method access

This method is invoked using a [user-controlled value](1), which may allow remote code execution.
window["HTMLElement" + message.name](message.payload); // OK - concatenation restricts choice of methods
window[`HTMLElement${message.name}`](message.payload); // OK - concatenation restricts choice of methods

function f() {}
f[message.name](message.payload)(); // NOT OK, but reported by UnsafeDynamicMethodAccess.ql [INCONSISTENCY]

Check failure

Code scanning / CodeQL-project6-javascript

Unsafe dynamic method access Critical

This method is invoked using a
user-controlled value
, which may allow remote code execution.

Check failure

Code scanning / CodeQL-project6-javascript

Unsafe dynamic method access

This method is invoked using a [user-controlled value](1), which may allow remote code execution.

obj[message.name](message.payload); // NOT OK

Check failure

Code scanning / CodeQL-project6-javascript

Unvalidated dynamic method call High

Invocation of method with
user-controlled
name may dispatch to unexpected target and cause an exception.

Check failure

Code scanning / CodeQL-project6-javascript

Unvalidated dynamic method call

Invocation of method with [user-controlled](1) name may dispatch to unexpected target and cause an exception.

window[ev](ev); // NOT OK, but reported by UnsafeDynamicMethodAccess.ql [INCONSISTENCY]

Check failure

Code scanning / CodeQL-project6-javascript

Unsafe dynamic method access Critical

This method is invoked using a
user-controlled value
, which may allow remote code execution.

Check failure

Code scanning / CodeQL-project6-javascript

Unsafe dynamic method access

This method is invoked using a [user-controlled value](1), which may allow remote code execution.
});
Loading