Skip to content

Commit 8efaa5d

Browse files
Copilothvitved
andauthored
Fix imprecise patterns in isSubprocessTarExtraction predicate
Use regexpMatch instead of matches to avoid false positives: - Command name: regexpMatch(\"(.*/)?tar\") to match only \"tar\" or paths ending in \"/tar\" - Extraction flag: regexpMatch(\"-[a-zA-Z]*x[a-zA-Z]*\") to match only single-dash flags containing x Agent-Logs-Url: https://github.com/github/codeql/sessions/f31a3622-9b18-415f-85f1-62ec14a8319f Co-authored-by: hvitved <3667920+hvitved@users.noreply.github.com>
1 parent 88b36c4 commit 8efaa5d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

python/ql/lib/semmle/python/security/dataflow/TarSlipCustomizations.qll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ module TarSlip {
169169
.getMember(["run", "call", "check_call", "check_output", "Popen"])
170170
.getACall() and
171171
cmdList = call.getArg(0).asCfgNode() and
172-
// Command must be "tar" (possibly with a full path like "/usr/bin/tar")
173-
cmdList.getElement(0).getNode().(StringLiteral).getText().matches("%tar") and
174-
// At least one extraction-related flag must be present
172+
// Command must be "tar" or a full path ending in "/tar" (e.g. "/usr/bin/tar")
173+
cmdList.getElement(0).getNode().(StringLiteral).getText().regexpMatch("(.*/)?tar") and
174+
// At least one extraction-related flag must be present:
175+
// single-dash flags containing 'x' (like -x, -xf, -xvf) or the long option --extract
175176
exists(string flag |
176177
flag = cmdList.getElement(_).getNode().(StringLiteral).getText() and
177-
(flag.matches("%-x%") or flag = "--extract")
178+
(flag.regexpMatch("-[a-zA-Z]*x[a-zA-Z]*") or flag = "--extract")
178179
) and
179180
// At least one non-literal argument (the archive filename)
180181
exists(int i |

0 commit comments

Comments
 (0)