Skip to content

fix(main): resolve CodeQL alerts #38 and #42 in nx-npm-trust#115

Merged
ThePlenkov merged 4 commits intomainfrom
fix/main-health
Apr 21, 2026
Merged

fix(main): resolve CodeQL alerts #38 and #42 in nx-npm-trust#115
ThePlenkov merged 4 commits intomainfrom
fix/main-health

Conversation

@ThePlenkov
Copy link
Copy Markdown
Member

@ThePlenkov ThePlenkov commented Apr 21, 2026

Summary

Restores main to a clean state by fixing the two open GitHub Code Scanning
(CodeQL) alerts. Latest CI run on main is already green, and SonarCloud
findings are out of scope for this PR.

CI

  • Last run on main is green (CI workflow, run 24709517306). No CI fix needed.

Security (code-scanning)

  • js/incomplete-url-substring-sanitization — alert Update CI workflow for nx-cloud and ensure fix-ci runs #38 (tools/nx-npm-trust/src/plugin.ts).
    Replace url.includes('github.com') with a regex that anchors github.com
    as the actual host of the remote URL, covering https(s)://, git://,
    git+ssh://, ssh://, and SCP-style (git@github.com:...) remotes.
  • js/clear-text-logging — alert chore: remove redundant version input from manual workflow triggers #42 (tools/nx-npm-trust/src/check.ts).
    Rename report.checks.mfareport.checks.mfaPolicy. The field stores
    the npm publish policy (none / automatic), not an auth factor or
    secret; the rename removes the false-positive signal without suppressing
    the rule.

Quality / AI findings

  • SonarCloud (811 open issues) intentionally not addressed in this PR —
    will be handled separately to keep review scope small.

Test plan


Open in Devin Review

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced accuracy of GitHub repository detection by implementing stricter validation for git remote URLs.
  • Refactor

    • Updated internal data structure for improved organization of security policy configuration settings.

The previous `url.includes('github.com')` check matched github.com anywhere
in the remote URL, including in paths or subdomains such as
https://evil.example/github.com/x/y or https://github.com.attacker.com/x/y.
Replace the substring check with a regex that anchors github.com to the
actual host component for https(s)://, git://, git+ssh://, ssh://, and
SCP-style remotes.

Resolves code-scanning alert #38 (js/incomplete-url-substring-sanitization).
The field stores the configured npm publish MFA *policy* (e.g. `none`,
`automatic`), not a user authentication factor or secret. Logging it in
the structured JSON report is safe, but the CodeQL heuristic
`js/clear-text-logging` fired on the field name `mfa`. Rename clarifies
intent and removes the false-positive signal.

Resolves code-scanning alert #42 (js/clear-text-logging).
Copilot AI review requested due to automatic review settings April 21, 2026 08:35
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 21, 2026

Deploy Preview for adt-cli canceled.

Name Link
🔨 Latest commit 69e0e22
🔍 Latest deploy log https://app.netlify.com/projects/adt-cli/deploys/69e73effbd9ec300080a5980

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

Warning

Rate limit exceeded

@ThePlenkov has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 52 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 24 minutes and 52 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bdcaa1b0-ca1c-4088-a294-5fdec0db529b

📥 Commits

Reviewing files that changed from the base of the PR and between a8477a3 and 69e0e22.

📒 Files selected for processing (1)
  • tools/nx-npm-trust/src/plugin.ts
📝 Walkthrough

Walkthrough

Modified MFA configuration storage key in the check flow from report.checks.mfa to report.checks.mfaPolicy to distinguish publish-policy settings from user-secret data. Updated GitHub repository detection logic to use stricter URL pattern matching for github.com remotes, supporting multiple Git URL formats while rejecting non-GitHub hosts.

Changes

Cohort / File(s) Summary
MFA Policy Storage
tools/nx-npm-trust/src/check.ts
Changed storage key for configured MFA target from report.checks.mfa to report.checks.mfaPolicy in the --fix flow to distinguish publish-policy configuration from user authentication data.
GitHub Remote Detection
tools/nx-npm-trust/src/plugin.ts
Replaced permissive substring check with stricter anchored regex pattern in detectGithubRepo() to validate github.com remotes, supporting HTTPS, SSH, and SCP-style URL formats while correctly rejecting non-GitHub hosts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A storage key renamed with care,
MFA policies now have their own lair,
GitHub detection grows wise and precise,
Regex patterns refined—oh so nice!
Trust in the tools, they're better each day.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main purpose of the pull request: resolving two specific CodeQL security alerts (#38 and #42) in the nx-npm-trust tool.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/main-health

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@amazon-q-developer amazon-q-developer Bot left a comment

Choose a reason for hiding this comment

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

This PR successfully resolves both CodeQL security alerts with appropriate fixes. The changes correctly address:

  1. Alert #38 (js/incomplete-url-substring-sanitization in plugin.ts): Replaced the vulnerable substring check with a comprehensive regex that properly validates github.com as the actual host, preventing URL manipulation attacks.

  2. Alert #42 (js/clear-text-logging in check.ts): Renamed mfa to mfaPolicy to accurately reflect that the field stores a policy value, not sensitive authentication data, eliminating the false positive.

Both fixes are well-implemented, maintain backward compatibility, and include clear documentation explaining the security rationale. No blocking issues identified.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Apr 21, 2026

View your CI Pipeline Execution ↗ for commit 69e0e22

Command Status Duration Result
nx affected -t lint test build e2e-ci --verbose... ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-21 09:11:27 UTC

@kilo-code-bot
Copy link
Copy Markdown

kilo-code-bot Bot commented Apr 21, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • tools/nx-npm-trust/src/check.ts - No issues
  • tools/nx-npm-trust/src/plugin.ts - No issues

Latest changes (commit 69e0e22): The refactor addresses a previously noted security concern:

  1. Strict owner/repo validation: Added OWNER_REPO regex (^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$) to validate the extracted owner/repo before it flows to the shell command (--trust-repo=${trustRepo}). This prevents shell metacharacters (;, |, $, backticks, etc.) from being injected.

  2. Fixed SCP/URL-form detection bug: Added !raw.includes('://') guard to prevent proper URL-form remotes with user/port (e.g., ssh://git@github.com:22/owner/repo) from being incorrectly parsed as SCP-style.

  3. Improved URL path handling: Changed from .replace(/^\//, '') to .replace(/^\/+|\.git$/g, '') to handle multiple leading slashes and strip .git in one operation.

The changes are well-documented with clear JSDoc comments explaining the security rationale. No issues found.


Reviewed by minimax-m2.5-20260211 · 450,971 tokens

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes two open CodeQL alerts in the internal nx-npm-trust tool by tightening GitHub remote URL detection and avoiding a clear-text-logging false positive in the JSON report output.

Changes:

  • Harden GitHub repo detection by matching github.com only as the actual remote host (not an arbitrary substring).
  • Rename the JSON report field from report.checks.mfa to report.checks.mfaPolicy to avoid CodeQL js/clear-text-logging heuristics.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tools/nx-npm-trust/src/plugin.ts Replaces substring host check with an anchored regex for GitHub remote parsing.
tools/nx-npm-trust/src/check.ts Renames the report field used to record the package MFA publish policy.

coderabbitai[bot]

This comment was marked as resolved.

Split host extraction into two small paths: `new URL()` for proper URL
schemes and a trivial SCP-style regex for `user@host:path`. The
combined regex in the previous commit had cyclomatic complexity 31 (> 20
allowed by SonarCloud `typescript:S5843`). Behaviour and the
`js/incomplete-url-substring-sanitization` fix are preserved — host
match is now anchored via `URL.hostname` or an explicit SCP host
capture, so substrings like `github.com.attacker.com` still cannot
match.

Resolves SonarCloud issue typescript:S5843 on fix/main-health.
devin-ai-integration[bot]

This comment was marked as resolved.

… owner/repo)

Addresses two bot review findings on PR #115:

* Devin Review — the SCP-style regex `^[^@\s]+@([^:]+):(.+)$` falsely
  matched URL-form remotes that contain both `user@` and a `:port`
  segment, e.g. `ssh://git@github.com:22/abapify/adt-cli.git`. The port
  was captured as part of the path and then rejected by parseOwnerRepo,
  silently disabling trusted-publisher auto-detection. The SCP branch is
  now skipped whenever the input contains `://`, so URL-form remotes
  fall through to `new URL()`.

* CodeRabbit — the previous shape regex `[^/]+/[^/.]+?` rejected valid
  GitHub repos with dots in the name (e.g. `owner/repo.name`) and
  accepted shell metacharacters in the owner segment. The value flows
  unquoted into a shell command at `plugin.ts` line ~126
  (`--trust-repo=${trustRepo}`), so a strict allow-list is enforced
  before return: `^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$`. This accepts
  dotted repos and rejects anything that could be interpreted by a shell.
@sonarqubecloud
Copy link
Copy Markdown

@ThePlenkov ThePlenkov merged commit 3f27dad into main Apr 21, 2026
13 checks passed
@ThePlenkov ThePlenkov deleted the fix/main-health branch April 21, 2026 09:16
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