Ship only runtime files in packaged gem to eliminate scanner false positives#721
Open
tmertens wants to merge 1 commit intoauth0:masterfrom
Open
Ship only runtime files in packaged gem to eliminate scanner false positives#721tmertens wants to merge 1 commit intoauth0:masterfrom
tmertens wants to merge 1 commit intoauth0:masterfrom
Conversation
The gemspec used `git ls-files` to populate `s.files`, which pulled every tracked file — Gemfile, Gemfile.lock, examples/, spec/, .github/, .devcontainer/, etc. — into the published gem. Downstream vulnerability scanners (AWS ECR, Snyk, Trivy, Grype) parse those bundled Gemfile.lock and example-app Gemfiles and report findings against dependencies that are never loaded at runtime, producing large volumes of false positives for gem consumers. Switch to an explicit allow-list covering only the files needed to load and run the gem: lib/**/*.rb, LICENSE, README.md, CHANGELOG.md, auth0.gemspec, and .version. Drop s.test_files (deprecated by RubyGems) and s.executables (no tracked bin/ entries exist). Package contents drop from ~385 files to 51. Refs auth0#720
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Fixes #720.
Updates
auth0.gemspecso the published gem contains only the files required to load and run the gem, rather than every file tracked by git.Before (current behavior):
This packaged ~385 files into every release of
auth0, including:GemfileandGemfile.lockexamples/ruby-api/(with its ownGemfile/Gemfile.lock)examples/ruby-on-rails-api/— a full Rails application with its ownGemfilespec/(unit + integration specs and VCR fixtures).github/,.devcontainer/,.bundle/,Guardfile,Rakefile,Dockerfile, CI config, etc.After:
The packaged gem now contains only
lib/**/*.rbplusLICENSE,README.md,CHANGELOG.md,auth0.gemspec, and.version— 51 files total.s.test_filesis removed — it has been deprecated by RubyGems and there is no reason to ship specs in the installed gem.s.executablesis removed because no files underbin/are tracked in git (the directory contains only local bundler binstubs).Why this matters
Enterprise vulnerability scanners (AWS ECR, Snyk, Trivy, Grype, etc.) parse every
Gemfile.lockthey find inside a container image or installed gem path. Because the publishedauth0gem currently ships multipleGemfile.lockfiles (the gem's own, plus the ones inside each example app), scanners report vulnerabilities againstactivesupport,rails,sinatra,puma, and other dev/example dependencies thatauth0never loads at runtime.Every consumer of the gem then has to triage or suppress those findings, even though the flagged dependencies are not actually present in their dependency graph. Removing those files from the package eliminates the false positives at the source.
Secondary benefit: significant reduction in gem size and install footprint.
Size impact
Measured against the installed
auth0-5.18.1gem from the current release:.gemfileThe on-disk reduction is larger than the
.gemreduction because the embedded Rails example (examples/ruby-on-rails-api/) is mostly text/config that compresses well in the gem tarball but inflates substantially on extraction.References
files: https://guides.rubygems.org/specification-reference/#filestest_files: You can make hidden gems. It kinda breaks things and it's maybe a security vulnerability. Hiiiiii, everybody! 👋 ruby/rubygems#2430Testing
Verified locally by rebuilding the gem and inspecting its contents:
The packaged gem contains only
lib/**/*.rb,LICENSE,README.md,CHANGELOG.md,auth0.gemspec, and.version. Nothing that was previously importable fromlib/has been removed, so no existing code paths or public APIs are affected. Existing CI (unit specs, integration specs, rubocop) continues to run against the untouched working tree — the change is strictly in gem packaging metadata.Note on tests: this change only affects gem packaging metadata (
s.files), which is exercised bygem buildrather than by the gem's spec suite. If the maintainers would like a dedicated test asserting the packaged file list (e.g. usingGem::Specification.load('auth0.gemspec').files), I'm happy to add one — let me know which style fits best.Checklist