mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Python: Add modelling for zstd.compression
See https://docs.python.org/3/library/compression.zstd.html for information about this library. As far as I can tell, the `zstd` library is not vulnerable to things like ZipSlip, but it _could_ be vulnerable to a decompression bomb attack, so I extended those models accordingly.
This commit is contained in:
@@ -364,6 +364,46 @@ module Lzma {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Provides sinks and additional taint steps related to the `zstd` library in Python 3.14+. */
|
||||||
|
module Zstd {
|
||||||
|
private API::Node zstdInstance() {
|
||||||
|
result = API::moduleImport("compression").getMember("zstd").getMember(["ZstdFile", "open"])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Decompression Sinks of `zstd` library
|
||||||
|
*
|
||||||
|
* `zstd.open(sink)`
|
||||||
|
* `zstd.ZstdFile(sink)`
|
||||||
|
*
|
||||||
|
* only read mode is sink
|
||||||
|
*/
|
||||||
|
class DecompressionSink extends DecompressionBomb::Sink {
|
||||||
|
DecompressionSink() {
|
||||||
|
exists(API::CallNode zstdCall | zstdCall = zstdInstance().getACall() |
|
||||||
|
this = zstdCall.getParameter(0, "filename").asSink() and
|
||||||
|
(
|
||||||
|
not exists(
|
||||||
|
zstdCall
|
||||||
|
.getParameter(1, "mode")
|
||||||
|
.getAValueReachingSink()
|
||||||
|
.asExpr()
|
||||||
|
.(StringLiteral)
|
||||||
|
.getText()
|
||||||
|
) or
|
||||||
|
zstdCall
|
||||||
|
.getParameter(1, "mode")
|
||||||
|
.getAValueReachingSink()
|
||||||
|
.asExpr()
|
||||||
|
.(StringLiteral)
|
||||||
|
.getText()
|
||||||
|
.matches("%r%")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `io.TextIOWrapper(ip, encoding='utf-8')` like following:
|
* `io.TextIOWrapper(ip, encoding='utf-8')` like following:
|
||||||
* ```python
|
* ```python
|
||||||
|
|||||||
Reference in New Issue
Block a user