Skip to content

Add JSON API for uploading and viewing Gemfile.lock reports - #103

Open
etagwerker wants to merge 5 commits into
mainfrom
json-api
Open

etagwerker wants to merge 5 commits into
mainfrom
json-api

Conversation

@etagwerker

Copy link
Copy Markdown
Member

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:

  • Bug fix
  • Feature
  • Chore

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?

  • Automated tests
  • Manual tests

What manual tests have been run?

Hitting the API with curl

What browsers did you test it on (if applicable)?

  • Chrome
  • Firefox
  • Edge
  • Safari

What devices did you test it on (if applicable)?

  • Laptop / PC
  • Tablet
  • Mobile

etagwerker and others added 5 commits December 3, 2026 16:27
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add JSON API

2 participants