OWASP 2017 A9: Using Components with Known Vulnerabilities
Equifax had sixty-seven days to install a patch that already existed.
Using Components with Known Vulnerabilities is a security vulnerability you inherit: your application runs a library, framework or server version with a published flaw that attackers already know how to use. It is number nine on the 2017 Top 10 from the Open Web Application Security Project (OWASP). It kept the same name and the same place it had in 2013. Almost everything around it changed.
When the item first appeared, the hard part was knowing what you ran. The 2013 essay covered that ground: Heartbleed, Shellshock, and building an inventory. Five years on, the defining breach of 2017 hit a company that had the patch and a written rule for how fast to apply it. The risk now sits in the days between the advisory and the install, and in libraries nobody chose on purpose.
What changed from 2013
The 2017 text moves in three directions.
- Speed. The 2013 text said to keep components up to date. The 2017 text says that patching on a monthly or quarterly change cycle is itself a sign you are vulnerable.
- Reach. Both editions say to inventory dependencies. The 2017 text spells out code that runs in the browser as well as on the server, and nested dependencies (the libraries your libraries pull in) as well as the ones you chose.
- Source. New advice: take components only from official sources over secure links, prefer signed packages, and watch for libraries nobody maintains any more.
OWASP also moved its rating for how hard the problem is to detect from difficult to average, in step with the tooling now available, and noted that, depending on what you protect, this item might deserve the top spot. Its example is CVE-2017-5638, the Struts bug behind Equifax.
Sixty-seven days at Equifax
Apache Struts is a widely used Java web framework. On March 7, 2017, the project disclosed CVE-2017-5638 (CVE, Common Vulnerabilities and Exposures, is the public naming system for security flaws), a flaw in the parser Struts uses for file uploads, and released fixed versions 2.3.32 and 2.5.10.1. The parser mishandled errors while building an error message, and a crafted Content-Type header let a remote attacker run commands on the server. One request, no login. The National Vulnerability Database (NVD), the US government’s public catalog of known flaws, rates it critical.
A working exploit was public the same day, and Cisco’s Talos research group saw attacks begin almost at once.
Here is the timeline, from the former chief executive’s testimony to Congress in October 2017 and the House Oversight Committee report of December 10, 2018:
| Date (2017) | What happened |
|---|---|
| March 7 | Struts discloses the bug and ships fixed versions. |
| March 8 | US-CERT, the federal computer emergency team, alerts Equifax. |
| March 9 | An internal alert goes to about 430 staff. Company policy requires critical patches within 48 hours. |
| March 10 | First evidence of the bug being exploited at Equifax. |
| March 15 | Scans of 958 internet-facing addresses find no vulnerable Struts. |
| May 13 | Attackers enter through the consumer dispute portal, still on the old Struts. |
| July 29 and 30 | Suspicious traffic is spotted; the portal is taken offline. |
| September 7 | Equifax announces the breach. |
The count of people affected grew from 143 million at the announcement to 147.9 million by March 2018, with Social Security numbers, birth dates and addresses taken.
The congressional report explains how a 48-hour rule became a 67-day gap:
- Nobody owned the portal. No one was formally named its owner, so the alert reached hundreds of people and bound none of them.
- The knowledge was lost. Staff had found Struts running on that portal in January 2017, while fixing a different Struts issue, and never recorded it.
- The scanner looked in the wrong place. The open source scan ran against the root directory, not the subdirectory where Struts was listed.
- Nothing checked the result. The alert email had no follow-up to confirm that anyone had acted.
Every piece of a patch process existed: an alert list, a policy with a clock, a scanner. None was tied to a named person and a check that the fixed version was running in production. Nothing proved the patch happened.
The library you never chose
On March 23, 2018, the Struts team told users to upgrade Apache Commons FileUpload to 1.3.3 at once. Versions before it carry CVE-2016-1000031, a flaw that can let an attacker run code on the server. Most Struts developers never added Commons FileUpload to their project. Struts did, as a transitive dependency: a library your library depends on.
The trap: the newest release of the Struts 2.3 line, 2.3.36 from September 2018, still asks for FileUpload 1.3.2. A team that dutifully upgraded to it still ships the vulnerable library. Maven, the standard Java build tool, will show you:
$ mvn dependency:tree -Dincludes=commons-fileupload
[INFO] com.example:disputes:war:1.0
[INFO] \- org.apache.struts:struts2-core:jar:2.3.36:compile
[INFO] \- commons-fileupload:commons-fileupload:jar:1.3.2:compile
Vulnerable
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.36</version>
</dependency>
</dependencies>
Fixed
<dependencyManagement>
<dependencies>
<!-- Overrides the version Struts asks for. Remove when Struts ships 1.3.3. -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.36</version>
</dependency>
</dependencies>
A dependencyManagement entry sets a library’s version wherever it appears in the tree. Run the tree command again and the line reads 1.3.3. The 2.5 line of Struts, from 2.5.12 on, ships 1.3.3 itself, which is the better long-term fix.
JavaScript trees are far deeper. In early November 2018, a fresh install of nodemon, a popular development tool, could resolve this chain:
$ npm ls flatmap-stream
app@1.0.0
└─┬ nodemon@1.18.6
└─┬ pstree.remy@1.1.0
└─┬ ps-tree@1.1.0
└─┬ event-stream@3.3.6
└── flatmap-stream@0.1.1
Five levels down sat a package built to steal bitcoin.
The registry is a supply chain
event-stream is a small library for working with data streams, downloaded about two million times a week in November 2018. Someone offered its original author help with maintenance, and the author handed over publishing rights. What followed, from the npm registry’s own records and its incident report:
- September 9, 2018: version 3.3.6 adds a new dependency, flatmap-stream.
- September 16: version 4.0.0 drops it again, so the newest version looked clean.
- October 5: flatmap-stream 0.1.1 is published with an encrypted payload hidden in its minified (compressed, unreadable) file. The commits visible on event-stream’s GitHub page looked harmless; the code that ran lived in the package on the registry.
- November 20: after users traced an odd deprecation warning back to it, a public issue on event-stream raises the alarm.
- November 26 and 27: npm is notified, removes the malicious versions and takes control of event-stream.
The payload decrypted itself using the description of the top-level project as the key. Everywhere except one place, it did nothing. In the build of Copay, a bitcoin wallet app, it came alive and set out to steal keys from wallets holding more than 100 bitcoin or 1,000 Bitcoin Cash. Copay confirmed that versions 5.0.2 through 5.1.0 shipped with it. flatmap-stream was downloaded close to eight million times between its inclusion in September and its removal.
Why did it spread? ps-tree asked for event-stream ~3.3.0, which means any 3.3.x release. So 3.3.6 flowed into every new install without anyone changing a line. On November 26, ps-tree’s maintainers pinned exactly 3.3.4.
Three lessons most write-ups skip:
- A vulnerability scanner would not have caught it. Scanners compare your versions against a list of reported problems, and for seven weeks this package was on no list. Known-vulnerability checks are necessary, and not sufficient.
- Reading the repository is not reading the package. You install the archive published to the registry, not the code on GitHub. Review what
node_modulesactually contains. - A maintainer change is a security event. A new publisher on a package you depend on deserves the scrutiny of a new committer on your own code.
The registry’s fragility was already on record. On March 22, 2016, after npm handed a package name to a company in a naming dispute, the author of left-pad, an 11-line function for padding strings, unpublished all 273 of their packages in protest. Builds broke across thousands of projects, including Babel and React, for a few hours until npm restored it. npm then barred authors from unpublishing anything older than 24 hours without its support team, and now leaves a placeholder when a package is removed, so nobody can slip a malicious replacement in under the old name. Every name in your lock file is a promise made by a stranger, and the registry is part of your production system.
Make the build say no
A build that passes with a known critical flaw in it is the same failure as Equifax’s alert email: information without consequence. Make the check a gate.
Node.js. Two commands in the build script:
npm ci
npm audit --audit-level=critical
npm ci (npm 5.7.0, February 2018) installs exactly what the lock file says and fails if package.json and the lock file disagree, so a new 3.3.6 cannot slip in during the build. npm audit (npm 6, April 2018) checks every package in the lock file, at every depth, against npm’s advisory database and exits with an error when it finds something. The --audit-level flag, added in npm 6.4.0 in August 2018, sets the severity that fails the build. Without it, a single low finding fails the build, and teams soon learn to ignore a gate that is always red. Start at critical, then tighten to high.
Commit the lock file: it turns version ranges into a fixed list, and npm audit refuses to run without one. It also freezes vulnerable versions in place, which is why the two belong together.
Java. OWASP Dependency-Check matches every jar against the NVD. Add it to the build:
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>3.3.4</version>
<configuration>
<failBuildOnCVSS>7</failBuildOnCVSS>
<suppressionFile>dependency-check-suppressions.xml</suppressionFile>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
The setting that matters is failBuildOnCVSS, a threshold on the Common Vulnerability Scoring System (CVSS) score each flaw carries. Its default is 11. Scores run from 0 to 10, so out of the box the plugin writes a report and never fails a build. Set it to 7 and mvn verify fails on anything scored 7 or above, which catches both Java flaws in this essay.
Real projects need exceptions: false matches, or a flaw in a feature you have switched off. Give each one an expiry date, so it cannot quietly become permanent:
<?xml version="1.0" encoding="UTF-8"?>
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.2.xsd">
<suppress until="2019-01-15">
<notes>Accepted by the application owner until the January release.</notes>
<gav regex="true">^commons-fileupload:commons-fileupload:.*$</gav>
<cve>CVE-2016-1000031</cve>
</suppress>
</suppressions>
On January 15 the exception lapses and the build fails again.
Hosted code. Since November 2017, GitHub sends security alerts for vulnerable JavaScript and Ruby dependencies, on by default for public repositories and opt-in for private ones. Turn them on, and notice who receives them: the repository’s owners, not always the people running production. That is Equifax’s alert list again. Route the alert to whoever owns the deployed copy.
For browser libraries that never pass through npm, Retire.js does the same job.
A deadline measured in days
Exploitation of the Struts bug started within a day of disclosure. A monthly patch window hands attackers up to thirty days. My working rule: a critical flaw in a component reachable from the internet is fixed in production within 72 hours, by a named owner, and anything else within two weeks.
The deadline only means something with three things attached:
- An owner per application, recorded next to the component list. A distribution list owns nothing.
- Proof from production, not from the repository. Check what is deployed:
unzip -l disputes.war | grep WEB-INF/liblists the jars actually shipped. Equifax’s scanner looked in the wrong directory; do not assume yours looks in the right one. - Upgrades that are boring. Teams delay patches because upgrades break things. Tests on every build and small monthly upgrades turn a 72-hour deadline into routine.
A firewall rule can buy a few days, and it is not a fix. The CVE record for the Struts bug lists Content-Disposition and Content-Length as further ways to trigger it; a rule written only for Content-Type left those open.
How to test your own application
- Print the full tree. Run
mvn dependency:treeornpm ls, and count the packages you never chose. - Compare with production. List the jars or
node_moduleson a running server and diff them against the build. Old copies left by a deploy script are common. - Run the gate by hand.
npm audit --audit-level=criticalormvn verifywith the plugin above. Read the paths, not just the totals: the fix is often an override on a library three levels down. - Prove the gate closes. On a throwaway branch, add commons-fileupload 1.3.2 to a Maven project, or a package version with a published critical advisory to a Node project, and confirm the build fails. If it passes, your gate is decoration.
- Read lock file changes in review. Adding one package can add forty to the lock file. For new names deep in the tree,
npm view <package> time maintainersshows when each was created and who publishes it. - Look for abandonment. No release in years, or a sudden new publisher, is a risk before any CVE exists.
Checklist
- Commit lock files. Install from them with
npm ciin every build. - Fail the build on critical findings:
npm audit --audit-level=critical, Dependency-Check withfailBuildOnCVSSset below 11. - Give every suppression a reason, an owner and an expiry date.
- Override vulnerable transitive versions directly when the parent library is slow to update.
- Name an owner for every application and a deadline in days for critical fixes.
- Verify the patched version in production, not in the repository.
- Treat new dependencies and new maintainers as changes that need review.
The Struts patch was published the day the bug was. Everything that went wrong afterwards was process: an alert with no owner, a scan in the wrong folder, nothing to prove the fix was live. Five years after this item joined the list, knowing what you run is the floor. Closing the gap between advisory and install takes a build that refuses to ship known critical flaws and a named person with a deadline counted in days.