Repository navigation
Add JSON API for uploading and viewing Gemfile.lock reports - #103
Open
etagwerker wants to merge 5 commits into
Open
etagwerker wants to merge 5 commits into
etagwerker wants to merge 5 commits into
Conversation
POST /gemfiles and GET /gemfiles/:id now respond to JSON. JSON requests must send an X-API-Key header that matches one of the keys in the API_KEYS env var (comma-separated). HTML and PDF are unchanged and stay public. Closes #101 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…evision API clients store more than the title and url: the CVE and GHSA ids, the criticality and CVSS scores, the advisory's date, and the patched and unaffected versions are now in each advisory. JSON reports also say which ruby-advisory-db commit they were checked against, so a client can tell when to scan again. Each process used to update the database only at boot; it now also updates it before a scan once the last attempt is an hour old. Git runs with -C, since bundler-audit's update! and commit_id Dir.chdir the whole process while Puma serves requests from other threads. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Each key has a name and a value. The value is generated with has_secure_token when you create a key with just a name. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The plain-text key is only available on the record that created it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical issues allow authentication bypass for JSON responses and can label scan findings with the wrong commit revision.
3 open issues
What changed in this PR
Adds JSON upload and retrieval of Gemfile.lock audit reports for #101, alongside the existing public HTML and PDF endpoints.
Changes:
- Adds JSON responses and database-backed API key authentication.
- Expands advisory details and adds database refresh and revision reporting.
- Documents API usage and adds authentication, report, and database tests.
| File | Description |
|---|---|
| test/models/gemfile_test.rb | Tests expanded advisory attributes. |
| test/models/api_key_test.rb | Tests key generation, hashing, and validation. |
| test/lib/bundler_audit_database_preparer_test.rb | Tests refresh timing, updates, and revisions. |
| test/controllers/gemfiles_controller_test.rb | Tests JSON authentication and responses. |
| README.md | Documents API provisioning, usage, and report fields. |
| lib/bundler_audit_database_preparer.rb | Adds timed refreshes and revision lookup. |
| db/schema.rb | Includes the API keys table. |
| db/migrate/20261204025827_create_api_keys.rb | Creates indexed API key storage. |
| app/models/gemfile.rb | Expands advisories and refreshes before scanning. |
| app/models/api_key.rb | Generates and authenticates hashed keys. |
| app/controllers/gemfiles_controller.rb | Adds authenticated JSON responses. |
| .reek.yml | Adds exclusions for new migration and tests. |
Review effort: Balanced
| end | ||
|
|
||
| def json_request? | ||
| request.format.json? |
| id: file.alpha_id, | ||
| vulnerabilities_count: vulnerabilities_count(vulnerabilities), | ||
| **vulnerabilities, | ||
| advisory_database: BundlerAuditDatabasePreparer.revision |
| end | ||
|
|
||
| def authenticate_api_key | ||
| return if ApiKey.valid_key?(request.headers[API_KEY_HEADER]) |
This branch has not been deployed
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.


POST /gemfiles and GET /gemfiles/:id now respond to JSON. JSON requests must send an X-API-Key header that matches one of the keys in the API_KEYS env var (comma-separated). HTML and PDF are unchanged and stay public.
Closes #101
IMPORTANT: please be descriptive and provide all required information. Make sure you provide all the information needed for others to review your PR. On sections marked “if applicable”, if that section is not applicable make sure to delete it. Additionally, if your PR closes any open GitHub issues, make sure you include Closes #XXXX in your comment or use the option on the PR's sidebar to add related issues to auto-close the issue that your PR fixes.
What is this PR:
Description:
Please include a summary of the change and which issue is fixed or which feature is introduced. If changes to the behaviour are made, clearly describe what changes.
Screenshots:
N/A because this is an API feature.
Related story:
Fixes #101
Related links (if applicable):
N/A
How has this been tested?
What manual tests have been run?
Hitting the API with
curlWhat browsers did you test it on (if applicable)?
What devices did you test it on (if applicable)?