SlideShare a Scribd company logo
Protecting your organization
against attacks via the
build system
Louis Jacomet - Gradle Inc.
@ljacomet
Louis Jacomet
Gradle, Inc.
Lead Software Engineer
Dependency Management / JVM Team at Gradle
Supply chain attacks are no longer an hypothesis
A supply-chain attack is an indirect attack which targets the tools, automatic software
updates or supply chain in general, in order to introduce malicious code or dependencies into
existing software, without the developers being aware.
The consequence of those attacks may be catastrophic as they are easily unnoticed and
usually scale out because of the end targets: mobile applications for example.
There’s evidence of such attacks in the wild. Some are suspected to be issued from Nation
State Actors.
CCleaner/Asus
• Hacked into (auto) update systems
• Tool update installed a backdoor (ShadowPad) on machines
• Performed a follow-up attack against high value targets
https://www.wired.com/story/inside-the-unnerving-supply-chain-attack-that-corrupted-ccleaner/
MS Tools attack
• Initial pattern similar to Asus / CCleaner, pointing to same
attackers
• Microsoft developer tools were maliciously modified
• Game companies used the compromised dev tools to sign
games
• Properly signed games are released with an embedded
backdoor
https://www.wired.com/story/supply-chain-hackers-videogames-asus-ccleaner/#
Homebrew - 30 minutes
from nobody to a commit
• Case study by Eric Holmes in 2018
• Found a leaked GitHub key on CI
• Committed to the main repo
• Profit Responsible disclosure and get the project protected
https://medium.com/@vesirin/how-i-gained-commit-access-to-homebrew-in-30-minutes-2ae314df03ab
23% of all security advisories against JS projects
refer to intentionally malicious packages
Jonathan Leitschuh, analyzing Npmjs advisories
“Maintainers of the RubyGems package repository
have yanked 18 malicious versions of 11 Ruby
libraries that contained a backdoor mechanism
and were caught inserting code that launched
hidden cryptocurrency mining operations inside
other people's Ruby projects.
https://www.zdnet.com/article/backdoor-code-found-in-11-ruby-libraries/
“When installing an average npm package, a user
implicitly trusts around 80 other packages due to
transitive dependencies.
https://blog.acolyer.org/2019/09/30/small-world-with-high-risks/
Real world dependency graph (Java)
A confusing dependency
• Android library for audio recording
• Thousands of stars on GitHub
• Available through JitPack
• Version that ends up on the app is different
• Executed code does not match the code on GitHub
• Attempts network calls, sharing phone model information
• Jitpack version was shadowed by another deploy to JCenter
https://blog.autsoft.hu/a-confusing-dependency/
“hackers don't attack individual devices or
networks directly, but rather the companies that
distribute the code used by their targets
https://www.wired.com/story/supply-chain-hackers-videogames-asus-ccleaner/#
Application building: Potential attack vectors
• New code
• CI infrastructure
• Dependencies
• Remote repositories
• Plugins (via plugin portal or Maven Central)
• Gradle/Maven distribution (and wrapper)
• Local file system
• Build cache / external services
New code and CI infrastructure
How to: compromise CI infrastructure
⬢Create a pull request
⬢Automatically build on CI (private
or public farm)
⬢Bitcoin all the things!
Variant: Compromising OSS developer machines
(example)
01 Submit a PR with compromised code (direct code, upgrade a plugin in the
build, introduce a new one, upgrade the wrapper, edit a build script, …)
02 Developer checks out the code locally and runs test
03 Profit!
Never “try out” PRs
• First, look at code, all files
• Don’t try directly on CI
• Or even locally!
• Be particularly picky on “obfuscated”
upgrades (plugin versions, …)
Pull request acceptance
• Use CLAs (reduces the risks)
• Perform light background verification of the author
• Review first and when you think it’s ok
• Check out the code
• Test it
• If on CI, use isolated, disposable build agents
Signing your commits
Git lets anyone use anyone’s identity

Signing proves your identity
Important for legal too (who contributed what)
Improving CI security
Disposable containers are a good idea for
security, however:
- They are bad for performance (extra
downloads, no Gradle daemon, build
bootstrapping, …)
- A single vulnerability in a container may
be enough to gain access to the host
Mitigating performance issues
Mitigating performance issues
The build cache makes it possible to reuse task outputs
from different build agents.
Needs secure connection between nodes.
Doesn’t deal with dependency downloads
The later can be handled by copying or sharing a
dependency cache (Gradle 6.1 and 6.2)
Dependencies, plugins and repositories
Our Commons: Maven Central / JCenter
Contains millions of artifacts, mostly published as convenience binaries, together with:
⬢ MD5 checksums → unsafe for a while
⬢ SHA1 checksums → really no longer safe
⬢ ASC signatures → not always safe
Checksums
• A checksum guarantees the integrity of the
artifact (if it’s safe…)
• Repository checksums may be compromised
too!
• Use checksums from a different source
(website)
• Publish checksums separately on a
different machine!
• Gradle 6 publishes SHA256 and SHA512
There are broken checksums on Maven Central.
JCenter computes SHA1/MD5 on demand.
Signatures
- A signature guarantees the origin of the
artifact (if private key didn’t leak)
- Commonly uses PGP
- Harder for casual developers to check
But:
- Keys sometimes lost
- Malicious authors can sign too
- ASC files use checksums too!
Verifying dependencies with Gradle
⬢Supported in Gradle core -
Requires Gradle 6.2
⬢Can check plugins in addition to
regular dependencies
⬢Supports checking metadata -
pom.xml, .module, …
⬢Can be checksum or signature
based
⬢Ability to generate first iteration of
the file
Verification in Maven
⬢ Requires an external plugin
⬢ Only cover dependencies, not plugins
⬢ Doesn’t support checking metadata - pom.xml
Inconsistent repositories
Different repositories may contain different artifacts or
metadata for a single release!
e.g: org.eclipse.core.runtime:3.12.0 has different
dependency versions between Central and JCenter!
Malicious repositories
Bintray had a vulnerability which allowed any
user to publish dependencies on any GAV
coordinates, shadowing any real dependency!
Man In The Middle Attack
25% of Maven Central downloads are still using
HTTP
Gradle deprecates HTTP downloads and
decommissions HTTP-based services (denied on
January 15th, 2020)
Also look at https://github.com/spring-io/nohttp
Solved
GitHub package registry
GitHub offers custom packages publications, effectively
allowing anyone to publish any module on a GitHub
Maven repository.
Trusting the source becomes extremely important!
(Currently requires a token to access)
Malicious repositories
(Maven)
Maven uses the declared repositories of all
dependencies during resolution.
Any repository can use the id of an existing one
(try: central)
As a consequence it’s easy to introduce
malicious dependencies in any build!
Repository filtering with Gradle
⬢Know where your dependencies
come from - Precisely tell Gradle
what repository contains what
dependency
⬢Avoid leaking details about your
organization - Avoids pinging
external repositories for your
internal coordinates!
⬢Avoids ordering issues -
Repositories can be listed in any
order if they are mutually exclusive
⬢Improves performance - No
unnecessary lookups
repositories {
jcenter {
content {
includeGroup("junit")
includeGroup("com.google.guava")
}
}
maven {
name = "myCompanyRepo"
content {
includeGroupByRegex("com.mycompany..*")
}
}
}
Dealing with vulnerable
dependencies
Dependency lifecycle doesn’t end at
publication:
- Bugs are discovered
- Vulnerabilities are discovered
- Bad metadata is published
Using rich versions in Gradle
⬢Rich versions - Allows more
accurate model of why a
dependency is needed
⬢Graph wide - Opinions of
transitive dependencies matter
⬢Allows enriching the graph with
new constraints - Consumers can
tell something about transitives
⬢Component metadata rules - For
amending existing metadata
dependencies {
implementation("org.apache.commons:commons-compress") {
version {
strictly("[1.0, 2.0[")
prefer("1.19")
reject("1.15", "1.16", "1.17", "1.18")
}
because("Versions 1.15-1.18 have a CVE")
}
}
Can be added dynamically
Tooling
Gradle wrapper checksum verification
⬢Gradle wrapper will verify
distribution checksums - On
every invocation
⬢But you need to manually check
the wrapper checksum itself - To
avoid a compromised wrapper!
⬢Expected checksum is checked
in - Using a compromised
distribution requires access to the
source repository
In gradle-wrapper.properties:
distributionSha256Sum=371cb9fbebbe9880d147f59bab36d61eee122854ef8c9ee1ecf12b82368bcf10
Gradle wrapper GitHub action
⬢GitHub action - To be added to
your workflow
⬢Validates the wrapper JAR
checksum itself - To avoid a
compromised wrapper!
A word about 3rd-party distributions
- Gradle “official” Docker image is not endorsed by
Gradle
- Debian and other distributions are not official
Gradle releases
- They use different dependencies
- They build their own!
- But they pretend to be Gradle (same
version number)
- Please always prefer official releases (and Gradle
wrapper if possible!)
Abusing external services
Using Gradle build cache as an example:
- Requires write access to the cache (so
compromised machine or malicious
employee)
- Write custom client to write malicious
output to the cache for a known key
(SHA1)
- Clients will download compromised entries
Reproducible builds
Any release should be reproducible byte to byte
In practice many things can go wrong:
- Dynamic dependencies (ranges, 1.+, latest, …)
- Undeclared inputs
- Timestamps/debug symbols/absolute paths/...
- Dependencies removed from remote repositories
- Compiler bugs
- etc
Different approaches to
reproducibility
The Apache Software Foundation™ way:
- Only sources matter
- Binaries (zip, jar, …) on Central or
dist.apache.org are convenience
- Trusting requires you to build from sources
Bootstrapping problem: what about transitive
dependencies?
Different approaches to
reproducibility
The Google way:
- Only sources matter
- No binaries, ever
- Single mono-repository
What about reuse?
We have to make compromises
⬢Dependency locking - Make sure
you can reuse the same versions
later
⬢Checksum verification - Binaries
will not be compromised
⬢Reproducible archives - Avoid
timestamps, consistent ordering of
archive entries, ...
See https://reproducible-builds.org/
If multiple organizations can build the same binaries, byte to
byte, from the same sources:
- Reinforces trust
- Improves build quality
- Makes it harder to compromise
A set of best practices:
Thank you!
Gradle: https://www.gradle.org
@ljacomet
References
⬢ Small world with high risks: a study of security threats in the npm ecosystem
⬢ Want to take over the Java ecosystem? All you need is a MITM!
⬢ The NPM package that walked away with all your passwords
⬢ A Post-Mortem of the Malicious event-stream backdoor
⬢ Backdoor code found in 11 Ruby libraries
⬢ ESlint Postmortem for Malicious Packages Published on July 12th, 2018
⬢ Inside the Unnerving CCleaner Supply Chain Attack
⬢ https://blog.autsoft.hu/a-confusing-dependency/

More Related Content

PPTX
Build Time Hacking
PPTX
Kubernetes and container security
PDF
Better Security Testing: Using the Cloud and Continuous Delivery
PPTX
Best Practices for Mission-Critical Jenkins
PDF
Deployment with Ruby on Rails
PPTX
DevSecCon Tel Aviv 2018 - End2End containers SSDLC by Vitaly Davidoff
PPT
Securing Apache Web Servers
PDF
Eclipsecon 2017 presentation
Build Time Hacking
Kubernetes and container security
Better Security Testing: Using the Cloud and Continuous Delivery
Best Practices for Mission-Critical Jenkins
Deployment with Ruby on Rails
DevSecCon Tel Aviv 2018 - End2End containers SSDLC by Vitaly Davidoff
Securing Apache Web Servers
Eclipsecon 2017 presentation

What's hot (20)

PPTX
Evaluating container security with ATT&CK Framework
PDF
Security DevOps - Staying secure in agile projects // OWASP AppSecEU 2015 - A...
PPT
20160221 va interconnect_pub
PDF
Security in serverless world
PPTX
Continuous Security Testing with Devops - OWASP EU 2014
PDF
Who *is* Jenkins?
PDF
Securing jenkins
PDF
Microservices for the Masses with Spring Boot, JHipster, and OAuth - South We...
PDF
Security Patterns for Microservice Architectures - ADTMag Microservices & API...
PDF
Strategy, planning and governance for enterprise deployments of containers - ...
PDF
Vulnerability Advisor Deep Dive (Dec 2016)
PPTX
Intro to Reactor
PDF
Introduction to Reactive Streams and Reactor 2.5
PDF
DevSecOps: What Why and How : Blackhat 2019
PDF
Monitoring in 2017 - TIAD Camp Docker
PPTX
Ci jenkins maven svn
PDF
Implementing Secure DevOps on Public Cloud Platforms
PDF
JHipster and Okta - JHipster Virtual Meetup December 2020
PDF
Jenkins tutorial
PDF
[Wroclaw #4] WebRTC & security: 101
Evaluating container security with ATT&CK Framework
Security DevOps - Staying secure in agile projects // OWASP AppSecEU 2015 - A...
20160221 va interconnect_pub
Security in serverless world
Continuous Security Testing with Devops - OWASP EU 2014
Who *is* Jenkins?
Securing jenkins
Microservices for the Masses with Spring Boot, JHipster, and OAuth - South We...
Security Patterns for Microservice Architectures - ADTMag Microservices & API...
Strategy, planning and governance for enterprise deployments of containers - ...
Vulnerability Advisor Deep Dive (Dec 2016)
Intro to Reactor
Introduction to Reactive Streams and Reactor 2.5
DevSecOps: What Why and How : Blackhat 2019
Monitoring in 2017 - TIAD Camp Docker
Ci jenkins maven svn
Implementing Secure DevOps on Public Cloud Platforms
JHipster and Okta - JHipster Virtual Meetup December 2020
Jenkins tutorial
[Wroclaw #4] WebRTC & security: 101
Ad

Similar to Protecting your organization against attacks via the build system (20)

PDF
#ATAGTR2019 Presentation "DevSecOps with GitLab" By Avishkar Nikale
PDF
Pragmatic Pipeline Security
PDF
Build cloud native solution using open source
PDF
Continuous Security for GitOps
PPTX
Aleksandr Kutsan "Managing Dependencies in C++"
PDF
Pluggable Infrastructure with CI/CD and Docker
PDF
What is the Secure Supply Chain and the Current State of the PHP Ecosystem
PDF
Watch How The Giants Fall: Learning from Bug Bounty Results
ODP
Effective DevSecOps
PDF
Fasten Industry Meeting with GitHub about Dependancy Management
PDF
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
PPT
Continuous Integration using Cruise Control
PDF
Exploring the GitHub Service Universe
PDF
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
PDF
BUILDING A CONTINUOUSLY INTEGRATING SYSTEM WITH HIGH SAFETY
PPTX
7 maven vsgradle
PDF
Stranger Danger: Your Java Attack Surface Just Got Bigger | JBCNConf 2022
PPTX
(Don't) Go Tracing Server Calls
PDF
Safeguarding artifact integrity in your Software Supply Chain
PDF
Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...
#ATAGTR2019 Presentation "DevSecOps with GitLab" By Avishkar Nikale
Pragmatic Pipeline Security
Build cloud native solution using open source
Continuous Security for GitOps
Aleksandr Kutsan "Managing Dependencies in C++"
Pluggable Infrastructure with CI/CD and Docker
What is the Secure Supply Chain and the Current State of the PHP Ecosystem
Watch How The Giants Fall: Learning from Bug Bounty Results
Effective DevSecOps
Fasten Industry Meeting with GitHub about Dependancy Management
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Continuous Integration using Cruise Control
Exploring the GitHub Service Universe
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
BUILDING A CONTINUOUSLY INTEGRATING SYSTEM WITH HIGH SAFETY
7 maven vsgradle
Stranger Danger: Your Java Attack Surface Just Got Bigger | JBCNConf 2022
(Don't) Go Tracing Server Calls
Safeguarding artifact integrity in your Software Supply Chain
Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...
Ad

More from Louis Jacomet (8)

PDF
Caching 101: Caching on the JVM (and beyond)
PDF
Data consistency: Analyse, understand and decide
PDF
Caching 101: sur la JVM et au delà
PDF
Caching 101: Caching on the JVM (and beyond)
PDF
Ehcache 3 @ BruJUG
PDF
Caching reboot: javax.cache & Ehcache 3
PDF
Caching reboot: javax.cache & Ehcache 3
PDF
Ehcache 3: JSR-107 on steroids at Devoxx Morocco
Caching 101: Caching on the JVM (and beyond)
Data consistency: Analyse, understand and decide
Caching 101: sur la JVM et au delà
Caching 101: Caching on the JVM (and beyond)
Ehcache 3 @ BruJUG
Caching reboot: javax.cache & Ehcache 3
Caching reboot: javax.cache & Ehcache 3
Ehcache 3: JSR-107 on steroids at Devoxx Morocco

Recently uploaded (20)

PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Transform Your Business with a Software ERP System
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
top salesforce developer skills in 2025.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
System and Network Administration Chapter 2
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Essential Infomation Tech presentation.pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
L1 - Introduction to python Backend.pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Digital Strategies for Manufacturing Companies
PTS Company Brochure 2025 (1).pdf.......
Design an Analysis of Algorithms II-SECS-1021-03
Upgrade and Innovation Strategies for SAP ERP Customers
Operating system designcfffgfgggggggvggggggggg
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Transform Your Business with a Software ERP System
Navsoft: AI-Powered Business Solutions & Custom Software Development
top salesforce developer skills in 2025.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
System and Network Administration Chapter 2
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Essential Infomation Tech presentation.pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
L1 - Introduction to python Backend.pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Which alternative to Crystal Reports is best for small or large businesses.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
How to Migrate SBCGlobal Email to Yahoo Easily

Protecting your organization against attacks via the build system

  • 1. Protecting your organization against attacks via the build system Louis Jacomet - Gradle Inc. @ljacomet
  • 2. Louis Jacomet Gradle, Inc. Lead Software Engineer Dependency Management / JVM Team at Gradle
  • 3. Supply chain attacks are no longer an hypothesis A supply-chain attack is an indirect attack which targets the tools, automatic software updates or supply chain in general, in order to introduce malicious code or dependencies into existing software, without the developers being aware. The consequence of those attacks may be catastrophic as they are easily unnoticed and usually scale out because of the end targets: mobile applications for example. There’s evidence of such attacks in the wild. Some are suspected to be issued from Nation State Actors.
  • 4. CCleaner/Asus • Hacked into (auto) update systems • Tool update installed a backdoor (ShadowPad) on machines • Performed a follow-up attack against high value targets https://www.wired.com/story/inside-the-unnerving-supply-chain-attack-that-corrupted-ccleaner/
  • 5. MS Tools attack • Initial pattern similar to Asus / CCleaner, pointing to same attackers • Microsoft developer tools were maliciously modified • Game companies used the compromised dev tools to sign games • Properly signed games are released with an embedded backdoor https://www.wired.com/story/supply-chain-hackers-videogames-asus-ccleaner/#
  • 6. Homebrew - 30 minutes from nobody to a commit • Case study by Eric Holmes in 2018 • Found a leaked GitHub key on CI • Committed to the main repo • Profit Responsible disclosure and get the project protected https://medium.com/@vesirin/how-i-gained-commit-access-to-homebrew-in-30-minutes-2ae314df03ab
  • 7. 23% of all security advisories against JS projects refer to intentionally malicious packages Jonathan Leitschuh, analyzing Npmjs advisories
  • 8. “Maintainers of the RubyGems package repository have yanked 18 malicious versions of 11 Ruby libraries that contained a backdoor mechanism and were caught inserting code that launched hidden cryptocurrency mining operations inside other people's Ruby projects. https://www.zdnet.com/article/backdoor-code-found-in-11-ruby-libraries/
  • 9. “When installing an average npm package, a user implicitly trusts around 80 other packages due to transitive dependencies. https://blog.acolyer.org/2019/09/30/small-world-with-high-risks/
  • 10. Real world dependency graph (Java)
  • 11. A confusing dependency • Android library for audio recording • Thousands of stars on GitHub • Available through JitPack • Version that ends up on the app is different • Executed code does not match the code on GitHub • Attempts network calls, sharing phone model information • Jitpack version was shadowed by another deploy to JCenter https://blog.autsoft.hu/a-confusing-dependency/
  • 12. “hackers don't attack individual devices or networks directly, but rather the companies that distribute the code used by their targets https://www.wired.com/story/supply-chain-hackers-videogames-asus-ccleaner/#
  • 13. Application building: Potential attack vectors • New code • CI infrastructure • Dependencies • Remote repositories • Plugins (via plugin portal or Maven Central) • Gradle/Maven distribution (and wrapper) • Local file system • Build cache / external services
  • 14. New code and CI infrastructure
  • 15. How to: compromise CI infrastructure ⬢Create a pull request ⬢Automatically build on CI (private or public farm) ⬢Bitcoin all the things!
  • 16. Variant: Compromising OSS developer machines (example) 01 Submit a PR with compromised code (direct code, upgrade a plugin in the build, introduce a new one, upgrade the wrapper, edit a build script, …) 02 Developer checks out the code locally and runs test 03 Profit!
  • 17. Never “try out” PRs • First, look at code, all files • Don’t try directly on CI • Or even locally! • Be particularly picky on “obfuscated” upgrades (plugin versions, …)
  • 18. Pull request acceptance • Use CLAs (reduces the risks) • Perform light background verification of the author • Review first and when you think it’s ok • Check out the code • Test it • If on CI, use isolated, disposable build agents
  • 19. Signing your commits Git lets anyone use anyone’s identity
 Signing proves your identity Important for legal too (who contributed what)
  • 20. Improving CI security Disposable containers are a good idea for security, however: - They are bad for performance (extra downloads, no Gradle daemon, build bootstrapping, …) - A single vulnerability in a container may be enough to gain access to the host
  • 22. Mitigating performance issues The build cache makes it possible to reuse task outputs from different build agents. Needs secure connection between nodes. Doesn’t deal with dependency downloads The later can be handled by copying or sharing a dependency cache (Gradle 6.1 and 6.2)
  • 24. Our Commons: Maven Central / JCenter Contains millions of artifacts, mostly published as convenience binaries, together with: ⬢ MD5 checksums → unsafe for a while ⬢ SHA1 checksums → really no longer safe ⬢ ASC signatures → not always safe
  • 25. Checksums • A checksum guarantees the integrity of the artifact (if it’s safe…) • Repository checksums may be compromised too! • Use checksums from a different source (website) • Publish checksums separately on a different machine! • Gradle 6 publishes SHA256 and SHA512
  • 26. There are broken checksums on Maven Central. JCenter computes SHA1/MD5 on demand.
  • 27. Signatures - A signature guarantees the origin of the artifact (if private key didn’t leak) - Commonly uses PGP - Harder for casual developers to check But: - Keys sometimes lost - Malicious authors can sign too - ASC files use checksums too!
  • 28. Verifying dependencies with Gradle ⬢Supported in Gradle core - Requires Gradle 6.2 ⬢Can check plugins in addition to regular dependencies ⬢Supports checking metadata - pom.xml, .module, … ⬢Can be checksum or signature based ⬢Ability to generate first iteration of the file
  • 29. Verification in Maven ⬢ Requires an external plugin ⬢ Only cover dependencies, not plugins ⬢ Doesn’t support checking metadata - pom.xml
  • 30. Inconsistent repositories Different repositories may contain different artifacts or metadata for a single release! e.g: org.eclipse.core.runtime:3.12.0 has different dependency versions between Central and JCenter!
  • 31. Malicious repositories Bintray had a vulnerability which allowed any user to publish dependencies on any GAV coordinates, shadowing any real dependency!
  • 32. Man In The Middle Attack 25% of Maven Central downloads are still using HTTP Gradle deprecates HTTP downloads and decommissions HTTP-based services (denied on January 15th, 2020) Also look at https://github.com/spring-io/nohttp Solved
  • 33. GitHub package registry GitHub offers custom packages publications, effectively allowing anyone to publish any module on a GitHub Maven repository. Trusting the source becomes extremely important! (Currently requires a token to access)
  • 34. Malicious repositories (Maven) Maven uses the declared repositories of all dependencies during resolution. Any repository can use the id of an existing one (try: central) As a consequence it’s easy to introduce malicious dependencies in any build!
  • 35. Repository filtering with Gradle ⬢Know where your dependencies come from - Precisely tell Gradle what repository contains what dependency ⬢Avoid leaking details about your organization - Avoids pinging external repositories for your internal coordinates! ⬢Avoids ordering issues - Repositories can be listed in any order if they are mutually exclusive ⬢Improves performance - No unnecessary lookups repositories { jcenter { content { includeGroup("junit") includeGroup("com.google.guava") } } maven { name = "myCompanyRepo" content { includeGroupByRegex("com.mycompany..*") } } }
  • 36. Dealing with vulnerable dependencies Dependency lifecycle doesn’t end at publication: - Bugs are discovered - Vulnerabilities are discovered - Bad metadata is published
  • 37. Using rich versions in Gradle ⬢Rich versions - Allows more accurate model of why a dependency is needed ⬢Graph wide - Opinions of transitive dependencies matter ⬢Allows enriching the graph with new constraints - Consumers can tell something about transitives ⬢Component metadata rules - For amending existing metadata dependencies { implementation("org.apache.commons:commons-compress") { version { strictly("[1.0, 2.0[") prefer("1.19") reject("1.15", "1.16", "1.17", "1.18") } because("Versions 1.15-1.18 have a CVE") } } Can be added dynamically
  • 39. Gradle wrapper checksum verification ⬢Gradle wrapper will verify distribution checksums - On every invocation ⬢But you need to manually check the wrapper checksum itself - To avoid a compromised wrapper! ⬢Expected checksum is checked in - Using a compromised distribution requires access to the source repository In gradle-wrapper.properties: distributionSha256Sum=371cb9fbebbe9880d147f59bab36d61eee122854ef8c9ee1ecf12b82368bcf10
  • 40. Gradle wrapper GitHub action ⬢GitHub action - To be added to your workflow ⬢Validates the wrapper JAR checksum itself - To avoid a compromised wrapper!
  • 41. A word about 3rd-party distributions - Gradle “official” Docker image is not endorsed by Gradle - Debian and other distributions are not official Gradle releases - They use different dependencies - They build their own! - But they pretend to be Gradle (same version number) - Please always prefer official releases (and Gradle wrapper if possible!)
  • 42. Abusing external services Using Gradle build cache as an example: - Requires write access to the cache (so compromised machine or malicious employee) - Write custom client to write malicious output to the cache for a known key (SHA1) - Clients will download compromised entries
  • 43. Reproducible builds Any release should be reproducible byte to byte In practice many things can go wrong: - Dynamic dependencies (ranges, 1.+, latest, …) - Undeclared inputs - Timestamps/debug symbols/absolute paths/... - Dependencies removed from remote repositories - Compiler bugs - etc
  • 44. Different approaches to reproducibility The Apache Software Foundation™ way: - Only sources matter - Binaries (zip, jar, …) on Central or dist.apache.org are convenience - Trusting requires you to build from sources Bootstrapping problem: what about transitive dependencies?
  • 45. Different approaches to reproducibility The Google way: - Only sources matter - No binaries, ever - Single mono-repository What about reuse?
  • 46. We have to make compromises ⬢Dependency locking - Make sure you can reuse the same versions later ⬢Checksum verification - Binaries will not be compromised ⬢Reproducible archives - Avoid timestamps, consistent ordering of archive entries, ... See https://reproducible-builds.org/ If multiple organizations can build the same binaries, byte to byte, from the same sources: - Reinforces trust - Improves build quality - Makes it harder to compromise A set of best practices:
  • 48. References ⬢ Small world with high risks: a study of security threats in the npm ecosystem ⬢ Want to take over the Java ecosystem? All you need is a MITM! ⬢ The NPM package that walked away with all your passwords ⬢ A Post-Mortem of the Malicious event-stream backdoor ⬢ Backdoor code found in 11 Ruby libraries ⬢ ESlint Postmortem for Malicious Packages Published on July 12th, 2018 ⬢ Inside the Unnerving CCleaner Supply Chain Attack ⬢ https://blog.autsoft.hu/a-confusing-dependency/