Skip to content

Commit 6d03548

Browse files
Copilothvitved
andauthored
Improve clarity of subprocess tar extraction detection patterns
Replace regexpMatch for command name with explicit equality check: - cmd = \"tar\" or cmd.matches(\"%/tar\") - clearly matches only exact \"tar\" or paths ending with \"/tar\" Keep flag check as regexpMatch since it naturally excludes double-dash flags 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 8efaa5d commit 6d03548

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,11 @@ 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" or a full path ending in "/tar" (e.g. "/usr/bin/tar")
173-
cmdList.getElement(0).getNode().(StringLiteral).getText().regexpMatch("(.*/)?tar") and
172+
// Command must be "tar" exactly or a path ending in "/tar" (e.g. "/usr/bin/tar")
173+
exists(string cmd |
174+
cmd = cmdList.getElement(0).getNode().(StringLiteral).getText() and
175+
(cmd = "tar" or cmd.matches("%/tar"))
176+
) and
174177
// At least one extraction-related flag must be present:
175178
// single-dash flags containing 'x' (like -x, -xf, -xvf) or the long option --extract
176179
exists(string flag |

0 commit comments

Comments
 (0)