mirror of
https://github.com/d9pouces/id_configurator.git
synced 2026-11-09 01:47:21 +01:00
feat: sanitize filenames in apt and yum modules to prevent path traversal
Signed-off-by: d9pouces <github@19pouces.net>
This commit is contained in:
@@ -54,6 +54,27 @@ def test_apply_writes_certificate_and_rebuilds_bundle(tmp_path) -> None:
|
||||
assert openssl_default.readlink().as_posix() == "/etc/ssl/certs/ca-certificates.crt"
|
||||
|
||||
|
||||
def test_apply_sanitizes_certificate_name_with_slash(tmp_path) -> None:
|
||||
data = {
|
||||
"uuid": "12345678-1234-5678-1234-567812345678",
|
||||
"organisation": "InterDiode",
|
||||
"configurations": {
|
||||
"certificates": [{"name": "../../evil", "content": CERT_CONTENT}]
|
||||
},
|
||||
}
|
||||
dst = tmp_path / "dst"
|
||||
context = Context(config=Configuration.model_validate(data), dst=dst, src=None)
|
||||
|
||||
CertificatesModule().apply(context)
|
||||
|
||||
local_cert = dst / "usr/local/share/ca-certificates/.._.._evil.crt"
|
||||
assert local_cert.read_bytes() == b"fake-cert-bytes"
|
||||
# The "/" must never be interpreted as a path separator: without
|
||||
# sanitizing, "../../evil" would have reshuffled the write up to
|
||||
# usr/local/evil.crt instead of staying under ca-certificates/.
|
||||
assert not (dst / "usr/local/evil.crt").exists()
|
||||
|
||||
|
||||
def test_apply_merges_conf_listed_and_local_certificates(tmp_path) -> None:
|
||||
src = tmp_path / "src"
|
||||
local_certs_dir = src / "usr/local/share/ca-certificates"
|
||||
|
||||
Reference in New Issue
Block a user