Skip to content

Commit 18137f5

Browse files
author
Alvaro Muñoz
committed
fix: take trigger events into consideration
Code Injection remote flow sources should be triggerable by the privileged event
1 parent 792e855 commit 18137f5

5 files changed

Lines changed: 193 additions & 166 deletions

File tree

ql/src/Security/CWE-094/CodeInjectionCritical.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ from CodeInjectionFlow::PathNode source, CodeInjectionFlow::PathNode sink, Event
2323
where
2424
CodeInjectionFlow::flowPath(source, sink) and
2525
inPrivilegedContext(sink.getNode().asExpr(), event) and
26+
source.getNode().(RemoteFlowSource).getEvent() = event and
2627
not exists(ControlCheck check | check.protects(sink.getNode().asExpr(), event, "code-injection")) and
2728
// exclude cases where the sink is a JS script and the expression uses toJson
2829
not exists(UsesStep script |
@@ -31,5 +32,6 @@ where
3132
exists(getAToJsonReferenceExpression(sink.getNode().asExpr().(Expression).getExpression(), _))
3233
)
3334
select sink.getNode(), source, sink,
34-
"Potential code injection in $@, which may be controlled by an external user.", sink,
35-
sink.getNode().asExpr().(Expression).getRawExpression()
35+
"Potential code injection in $@, which may be controlled by an external user ($@).", sink,
36+
sink.getNode().asExpr().(Expression).getRawExpression(), event,
37+
event.getLocation().getFile().toString()

ql/test/query-tests/Security/CWE-094/.github/actions/action5/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ runs:
1616
using: 'composite'
1717
steps:
1818
- shell: bash
19-
run: echo '${{ github.event.pull_request.body }}'
19+
run: echo '${{ github.event.issue.body }}'
2020
- name: Step
2121
id: step
2222
env:
@@ -25,7 +25,7 @@ runs:
2525
run: echo "result=$(echo $FOO)" >> $GITHUB_OUTPUT
2626
- id: step2
2727
env:
28-
FOO2: ${{ github.event.pull_request.body }}
28+
FOO2: ${{ github.event.issue.body }}
2929
shell: bash
3030
run: echo "result2=$(echo $FOO2)" >> $GITHUB_OUTPUT
3131
- name: Sink
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
- 'release/v*'
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
required: true
10+
description: 'Release'
11+
type: string
12+
13+
jobs:
14+
release-tag:
15+
runs-on: ubuntu-latest
16+
if: ${{ startsWith(github.event.head_commit.message, 'release:') }}
17+
steps:
18+
- name: Extract version and PR number from commit message
19+
id: extract_info
20+
shell: bash
21+
run: |
22+
echo "version=$( echo "${{ github.event.head_commit.message }}" | sed 's/^release: v\([0-9]\+\.[0-9]\+\.[0-9]\+\).*$/\1/' )" >> $GITHUB_OUTPUT
23+
echo "pr_number=$( echo "${{ github.event.head_commit.message }}" | sed 's/.*(\#\([0-9]\+\)).*$/\1/' )" >> $GITHUB_OUTPUT
24+
echo "release_branch=release/v$( echo "${{ github.event.head_commit.message }}" | sed 's/^release: v\([0-9]\+\.[0-9]\+\).*$/\1/' )" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)