Skip to content

New rake check - compare root url: to filename (without suffix)#1069

Open
jasnow wants to merge 1 commit into
rubysec:masterfrom
jasnow:url-filename-check
Open

New rake check - compare root url: to filename (without suffix)#1069
jasnow wants to merge 1 commit into
rubysec:masterfrom
jasnow:url-filename-check

Conversation

@jasnow
Copy link
Copy Markdown
Contributor

@jasnow jasnow commented May 24, 2026

Based on @simi's feedback during the past week or two, I tried to create a new "rake" lint check (rule) for root url: == basename(filenname).

  • First, since this is a new rule and the large number of failed checks on existing advisories, I decided to pick a start date to start applying it. I found that advisories with date: > "2026-05-09" all passed. I know this is a compromise but I hope the team agree that the new check is worth the compromise.

  • Second, I skipped the OSVDB advisories because they are very old and that database was removed from the web and internet archive.

@jasnow
Copy link
Copy Markdown
Contributor Author

jasnow commented May 24, 2026

Hint: If you want to see all the failed check, change the start date to 2000 and you will see all of them.

Comment thread spec/advisory_example.rb
url = advisory["url"]

# Extract last path segment from URL
url_root = File.basename(URI.parse(url).path)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if it would be useful to instead assert something like

expect(url).to include(filename_root)

resulting in a message like

expected "https://github.com/lsegal/yard/security/advisories/GHSA-3jfp-46x4-xgfj" to include "CVE-2026-41493"

Then the assertion would pass on URLs like https://www.cve.org/CVERecord?id=CVE-2026-45363 (see "/gems/jwt/CVE-2026-45363.yml").

Comment thread spec/advisory_example.rb
# Skip advisories older than start_date and old OSVDB advisories.
if advisory["date"] >= start_date and !filename_root.start_with?("OSVDB")
expect(filename_root).to eq(url_root),
"Expected filename '#{filename_root}' DOES NOT to match URL root '#{url_root}'"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This string is not used as the error message. RSpec will generate the right message based on the assertion. It can be removed.

Comment thread spec/advisory_example.rb
filename_root = File.basename(path, ".yml")

# 5/24/2026: May 9, 2026 is earliest start date with no failed checks.
start_date = Date.new(2026, 5, 9)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like this approach. I've heard this approach called "ratcheting", where you set a linting policy that is immediately in effect for new code/reports, but allows older code to pass; and then have the ability to then gradually apply it to the rest of the codebase/reports.

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.

2 participants