A dependency upgrade passed CVE scans. Why can security still break?
Question
You upgrade a Python helper library that unpacks uploaded .tar bundles into a sandbox folder. pip-audit and CVE scanners report zero advisories, and unit tests pass on normal files like report.txt. Yet the new version quietly changed its default to permissive extraction (filter="fully_trusted").
- Why do version numbers and CVE scanners miss this regression?
- Write an automated security regression check on synthetic
.tarfixtures (report.txt,../escape.txt, and an escaping symlink) that fails if anything extracts outsidedest.
import tarfile def unpack_bundle(tar_buf, dest): # Wrapper default changed during a dependency upgrade. with tarfile.open(fileobj=tar_buf) as tf: tf.extractall(dest, filter="fully_trusted")
Show hints (3)
- "CVES VERSUS DEFAULTS"
Advisory tools match known package CVEs. They cannot tell whether a clean release flipped a default like redirect following or symlink handling.
- "BUILD SYNTHETIC FIXTURES"
Create tiny in-memory
.tarbuffers inside a temp folder: a normal file, a../escape.txtentry, and a symlink pointing outsidedest. - "ASSERT THE BOUNDARY"
Pass explicit safe options (
filter="data"), assert that escaping entries raisetarfile.FilterError, and check that the parent folder stays clean.
Show checked explanation
Version checks and CVE scanners like pip-audit or npm audit only match known advisories. They miss a clean upgrade that flips a default like path filtering or redirect following. Set safe options explicitly (filter="data"), and run an automated regression test on synthetic bad fixtures that fails if anything writes outside dest.
import io import os import tarfile as tf import tempfile def probe(name, flt="data", link=""): buf = io.BytesIO() with tf.open(fileobj=buf, mode="w") as z: ti = tf.TarInfo(name) ti.type, ti.linkname = (tf.SYMTYPE, link) if link else (tf.REGTYPE, "") z.addfile(ti) with tempfile.TemporaryDirectory() as r: try: with tf.open(fileobj=io.BytesIO(buf.getvalue())) as z: z.extractall(os.path.join(r, "out"), filter=flt) return "escaped" if set(os.listdir(r)) - {"out"} else "ok" except tf.FilterError as err: return type(err).__name__ print(probe("report.txt"), probe("../escape.txt"), probe("l", "data", "../s")) print("unfiltered:", probe("../escape.txt", "fully_trusted"))
ok OutsideDestinationError LinkOutsideDestinationError unfiltered: escaped
Code run on CPython 3.12.10 with stdlib tarfile on synthetic safe, traversal, and symlink archives in temporary folders; official OWASP, Python tarfile, and npm audit links checked. Checked by an editor other than the author.
Walkthrough
Dependency scanners (pip-audit, npm audit, SCA tools) compare your lockfile versions against public CVE databases. A new major release that flips a default is often an intentional API change, not a CVE, so every advisory check stays green. Happy-path unit tests (report.txt) stay green too.
Only a behavioral security regression test catches the break. In probe above, Python builds tiny synthetic .tar archives in memory inside an isolated temporary directory:
report.txtextracts insideoutand returnsok.../escape.txtraisesOutsideDestinationErrorunderfilter="data", leaving the parent folder clean.- Symlink
l -> ../sraisesLinkOutsideDestinationErrorbefore any link is written. - Switching
fltto"fully_trusted"writes outsideoutsoset(os.listdir(r)) - {"out"}catches any escaping filename (unfiltered: escaped), immediately failing CI.
The same testing rule applies across every security-sensitive library you upgrade:
| library upgrade | silent default change | synthetic regression test in CI |
|---|---|---|
| Archive extractor | Relaxes .. or symlink filtering | Unpack synthetic ../escape.txt and outside symlink; assert error and clean parent dir |
| HTTP / URL client | Follows 302 redirects or keeps Authorization cross-origin | Hit local test 302 to disallowed host; assert redirect blocked or header stripped |
| HTML sanitizer | Allows extra tags or javascript: URLs | Pass synthetic risky HTML fixture; assert dangerous tags and schemes are removed |
Pair this with explicit safe configuration (filter="data", allow_redirects=False) so your safety guarantee never rests on an implicit library default.
Common mistakes
- Treating a clean
pip-auditornpm auditreport, or a bumped version number, as proof that an upgrade kept your security guarantees intact. - Relying on implicit library defaults instead of passing explicit options like
filter="data"orallow_redirects=Falsein your wrapper. - Testing only happy-path fixtures like
report.txton upgrade PRs, which never exercise path traversal, symlinks, or cross-origin redirects. - Asserting only that a helper "did not crash" instead of checking that the escaping file was rejected and never created outside
dest.
Follow-up questions
- "An HTTP client upgrade turned on automatic redirect following. How would you write a fast CI test for it?" Spin up a tiny local test server on
127.0.0.1that returns302to a disallowed target or second origin. Call your HTTP wrapper with a syntheticAuthorization: Bearer test_tokheader and assert that either redirects are refused or the header is stripped on the second hop. - "Should you stop running
pip-audit,npm audit, or CVE scanners if you have security regression tests?" No, because they catch different failures. Advisory scanners flag known CVEs in transitive packages you never wrote tests for. Regression tests confirm that your app's own security boundaries still hold after every upgrade. - "How do you avoid flaky or risky security tests in CI?" Use tiny self-contained synthetic fixtures in memory or temporary folders, and bind any local HTTP test server to loopback (
127.0.0.1). Never point tests at real secrets, real user data, or external hosts.
What a strong answer covers
Explains why version pins and CVE scans miss default-behavior regressions. Sets explicit safe options and writes fast CI tests on synthetic fixtures that directly assert the defense holds.
Open in interactive practice deck →