Skip to content

Commit 65b226d

Browse files
author
Alvaro Muñoz
authored
Merge pull request #12 from GitHubSecurityLab/ctx_expressions
feat(bash-step): Improve bash step accuracy
2 parents 0f73080 + 1cd3219 commit 65b226d

File tree

3 files changed

+8
-37
lines changed

3 files changed

+8
-37
lines changed

ql/lib/codeql/actions/dataflow/FlowSteps.qll

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ class AdditionalTaintStep extends Unit {
2121
abstract predicate step(DataFlow::Node node1, DataFlow::Node node2);
2222
}
2323

24-
// private class RunEnvToScriptStep extends AdditionalTaintStep {
25-
// override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
26-
// runEnvToScriptstep(pred, succ)
27-
// }
28-
// }
2924
/**
3025
* Holds if a Run step declares an environment variable, uses it in its script and sets an output in its script.
3126
* e.g.
@@ -34,11 +29,9 @@ class AdditionalTaintStep extends Unit {
3429
* env:
3530
* BODY: ${{ github.event.comment.body }}
3631
* run: |
37-
* INITIAL_URL=$(echo "$BODY" | grep -o 'https://github.com/github/release-assets/assets/[^ >]*')
38-
* echo "Cleaned Initial URL: $INITIAL_URL"
39-
* echo "::set-output name=initial_url::$INITIAL_URL"
40-
* echo "foo=$(echo $TAINTED)" >> $GITHUB_OUTPUT
41-
* echo "test=${{steps.step1.outputs.MSG}}" >> "$GITHUB_OUTPUT"
32+
* echo "::set-output name=foo::$BODY"
33+
* echo "foo=$(echo $BODY)" >> $GITHUB_OUTPUT
34+
* echo "foo=$(echo $BODY)" >> "$GITHUB_OUTPUT"
4235
*/
4336
predicate runEnvToScriptStoreStep(DataFlow::Node pred, DataFlow::Node succ, DataFlow::ContentSet c) {
4437
exists(RunExpr r, string varName, string output |
@@ -51,8 +44,7 @@ predicate runEnvToScriptStoreStep(DataFlow::Node pred, DataFlow::Node succ, Data
5144
output = line.regexpCapture(".*::set-output\\s+name=(.*)::.*", 1) or
5245
output = line.regexpCapture(".*echo\\s*\"(.*)=.*\\s*>>\\s*(\")?\\$GITHUB_OUTPUT.*", 1)
5346
) and
54-
// TODO: repalce script with line below
55-
script.indexOf("$" + ["", "{", "ENV{"] + varName) > 0
47+
line.indexOf("$" + ["", "{", "ENV{"] + varName) > 0
5648
) and
5749
succ.asExpr() = r
5850
)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,4 @@ import MyFlow::PathGraph
3737
from MyFlow::PathNode source, MyFlow::PathNode sink
3838
where MyFlow::flowPath(source, sink)
3939
select sink.getNode(), source, sink,
40-
"Potential injection from the ${{ " + sink.getNode().asExpr().(CtxAccessExpr).getExpression() +
41-
" }}, which may be controlled by an external user."
40+
"Potential expression injection, which may be controlled by an external user."

ql/src/test/.github/workflows/image_link_generator.yml

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,21 @@ jobs:
1717
env:
1818
BODY: ${{ github.event.comment.body }}
1919
run: |
20-
INITIAL_URL=$(echo "$BODY" | grep -o 'https://github.com/github/release-assets/assets/[^ >]*')
21-
echo "Cleaned Initial URL: $INITIAL_URL"
22-
echo "::set-output name=initial_url::$INITIAL_URL"
20+
echo "::set-output name=initial_url::$BODY"
2321
2422
- name: Get Redirected URL with Debugging
2523
id: curl
2624
env:
2725
INITIAL_URL: ${{ steps.extract-url.outputs.initial_url }}
2826
run: |
29-
REDIRECTED_URL=$(curl -L -o /dev/null -w %{url_effective} -sS "$INITIAL_URL")
30-
echo "Curl Command Executed"
31-
echo "Redirected URL: $REDIRECTED_URL"
32-
echo "::set-output name=redirected_url::$REDIRECTED_URL"
33-
27+
echo "redirected_url=$(echo $INITIAL_URL)" >> $GITHUB_OUTPUT
3428
- name: Trim URL after PNG
3529
id: trim-url
3630
env:
3731
REDIRECTED_URL: ${{ steps.curl.outputs.redirected_url }}
3832
run: |
39-
TRIMMED_URL=$(echo "$REDIRECTED_URL" | sed 's/\(.*\.png\).*/\1/')
40-
echo "Trimmed URL: $TRIMMED_URL"
41-
echo "::set-output name=trimmed_url::$TRIMMED_URL"
33+
echo "trimmed_url=$(echo $REDIRECTED_URL)" >> "$GITHUB_OUTPUT"
4234
4335
- name: Update Comment with New URL
44-
env:
45-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46-
COMMENT_URL: ${{ github.event.comment.url }}
47-
ORIGINAL_COMMENT_BODY: ${{ github.event.comment.body }}
4836
run: |
4937
NEW_COMMENT_BODY="Use this link to include this asset in your changelog: ${{ steps.trim-url.outputs.trimmed_url }}"
50-
UPDATED_COMMENT="${ORIGINAL_COMMENT_BODY} 👀 ${NEW_COMMENT_BODY}"
51-
52-
PAYLOAD=$(jq -n --arg body "$UPDATED_COMMENT" '{"body": $body}')
53-
curl -X PATCH \
54-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
55-
-H "Accept: application/vnd.github.v3+json" \
56-
"${COMMENT_URL}" \
57-
-d "$PAYLOAD"

0 commit comments

Comments
 (0)