ZTGIT

Dependencies are suppliers too: how ZTGIT filters Python and PHP packages before use

ZTGIT team

Dependencies are suppliers too: how ZTGIT filters Python and PHP packages before use

The problem: the installer trusts on your behalf

When someone runs pip install or composer install, the installer fetches the newest version that satisfies the project’s rules from a public repository, together with all of its dependencies. Each of those packages becomes code running in your environment, often already during installation.

That makes every dependency a supplier nobody hired. Software supply chain attacks target exactly this: a name that looks like a popular package, a hijacked maintainer account, a new version with a malicious install script.

Zero trust says nothing is trusted just because it arrives through the usual path. ZTGIT applies that to dependencies as well.

Python packages: an approved index

ZTGIT builds and services install Python packages from an in-house index with two levels:

  1. Cache of the public repository. Keeps what has already been downloaded, so builds do not depend on outside availability every time.
  2. Approved index. Serves only the package and version pairs on the approved list. A package outside the list, or a version other than the approved one, simply does not exist for the installer.

For a version to be added, the request goes through two independent checks:

  • ZTGIT-MalPkgScan: static analysis of the package looking for malicious behavior, such as downloading and running code at install time, data exfiltration and obfuscation.
  • ZTGIT-SBOMscan: known vulnerabilities (CVE) in the requested version.

The check covers the package and all of its dependencies. If a single dependency is rejected, the whole request is refused and an alert is raised.

One detail only showed up in testing: the version filter component we use let every version of an approved package through, not just the approved one. We fixed it with our own patch, covered by a test, before putting the index into use. It is the kind of flaw you only find by testing what the filter rejects, not just what it accepts.

PHP packages: a closed-list mirror

For PHP, ZTGIT runs a Composer mirror with a closed list of packages and versions. Installs point only to it, and every file comes with a verified hash. Asking for a package that is not on the list fails by design.

Adding a new package follows the same logic as the Python index: name and version, check, then publish. Automatic scanning of the whole list before each publication is being added to the process.

The code in the images: static and dynamic analysis

Dependencies are one part of the risk. The other is the code that goes inside each image. That is why the ZTGIT pipeline now runs:

  • SAST: static analysis of the source code, with open rules and every exception recorded with its reason;
  • DAST: tests against the running service, in a lab environment only.

Today this works in alert mode: critical and high findings are recorded and triaged, without blocking the build yet. Blocking comes after a few stable weekly runs. The difference between these scans is covered in SBOM, SCA, SAST and DAST: what each scan sees.

How it fits with the rest

The approved index and the mirror close the door for packages. Images keep following the path described in From source code to signed image: mirrored and pinned upstream, in-house build, SBOM, two scans with a gate, and cosign signing.

What we do not do yet

To be clear:

  • Reachability analysis (knowing whether the code actually uses the vulnerable part) is in development.
  • VEX statements (formally stating which vulnerabilities affect the product) are in development.
  • SAST and DAST do not block the build yet.

Takeaways

  • Treat every dependency as a supplier: someone has to approve it coming in.
  • Approve package and version, not just the name.
  • Check the whole dependency tree, not just the requested package.
  • Test what your filter rejects.

From the blog