Skip to content

fix(controls): trustedUrls bare-hostname matching and partial semver false positives#215

Open
12122J wants to merge 1 commit into
getplumber:mainfrom
12122J:fix/rego-policy-bugs
Open

fix(controls): trustedUrls bare-hostname matching and partial semver false positives#215
12122J wants to merge 1 commit into
getplumber:mainfrom
12122J:fix/rego-policy-bugs

Conversation

@12122J
Copy link
Copy Markdown

@12122J 12122J commented May 28, 2026

Summary

Fixes two independent Rego policy bugs:

Fix 1 — ISSUE-411 trustedUrls bare-hostname matching (#214)

pipelineMustNotExecuteUnverifiedScripts.trustedUrls had no effect on curl/wget commands that used a bare hostname without an http(s):// scheme, such as:

curl -sL firebase.tools | bash

The extractor regex https?://[^\s|;)'"]+ only captured schemed URLs, so bare-hostname tokens were never compared against trustedUrls patterns. The finding was always emitted regardless of the allowlist.

Root cause: _line_is_trusted extracted only https?:// URLs; bare hostnames like firebase.tools were invisible to the matcher.

Fix: Two additional _line_is_trusted rules extract bare hostname tokens (requiring at least one dot, no http prefix) and try matching them against each pattern — once directly ("firebase.tools") and once normalised to https:// ("https://firebase.tools").


Fix 2 — ISSUE-403 partial semver false positive (#157)

A component ref like @1 or @1.2 was incorrectly flagged as outdated when the latest version was 1.2.4. In GitLab component versioning, @1 means "latest 1.x.x" — it is always current within that major prefix and should never trigger ISSUE-403.

Root cause: The deny rule compared inc.ref != inc.current directly, so "1" != "1.2.4" always fired.

Fix: New _ref_is_partial_semver_prefix helper checks whether ref is a proper version prefix of current (e.g. "1" is a prefix of "1.2.4", "1.2" is a prefix of "1.2.4"). The deny rule now skips the finding when the prefix check passes.


Test plan

  • TestIssue411_UnverifiedScripts_TrustedBareHostname — new regression test, bare hostname in trustedUrls does not fire; untrusted URL still fires
  • TestIssue403_IncludesOutdated_PartialSemver — new regression test covers @1, @v1, @1.2 (no fire), and @1 / current=2.0.0 (fires)
  • All existing TestIssue411 and TestIssue403 cases continue to pass
  • make test passes clean

AI disclosure

This PR was written with Claude Code (claude-sonnet-4-6). All code was reviewed by the submitter; tests were run and confirmed passing before submission.

Closes #214
Closes #157

…false positives

Fixes two regression bugs in Rego policies:

1. ISSUE-411 (pipelineMustNotExecuteUnverifiedScripts): trustedUrls
   patterns were never matched against bare-hostname URLs (e.g.
   `curl -sL firebase.tools | bash`). The extractor only found
   https?:// URLs, so any curl/wget command using a bare hostname
   bypassed the allowlist entirely and was always reported.
   Fixed by adding two additional _line_is_trusted rules that extract
   bare hostname tokens and try matching them against each pattern both
   directly and with an https:// prefix.

2. ISSUE-403 (includes_outdated): a component ref like "@1" or "@1.2"
   was incorrectly flagged as outdated when the latest version was
   "1.2.4". In GitLab component semantics "@1" tracks the latest 1.x.x,
   so it is never out of date within that major prefix.
   Fixed by adding a _ref_is_partial_semver_prefix helper that checks
   whether ref is a proper version prefix of current and suppresses the
   finding when it is.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@thomasboni
Copy link
Copy Markdown
Contributor

Hello @12122J , thanks for this second PR :) We will review soon too

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

Labels

None yet

Projects

None yet

2 participants