Skip to content

[eslint-miner] eslint-factory: add no-path-startswith-without-separator rule - #75594

Merged
pelikhan merged 3 commits into
mainfrom
eslint-miner/no-path-startswith-without-separator-7d0e882b21d2ac1d
Nov 7, 2026
Merged

pelikhan merged 3 commits into
mainfrom
eslint-miner/no-path-startswith-without-separator-7d0e882b21d2ac1d

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Warning

Threat detection engine error

Threat detection could not complete its analysis due to a tooling error. This is not a security finding.

What happened

The threat detection results could not be parsed.

Review the workflow run logs to troubleshoot the error.

New rule: no-path-startswith-without-separator

Flags x.startsWith(root) where root is a bare path.resolve/join/normalize result (directly or via a single-assignment const). /work/repo-evil passes startsWith("/work/repo"), so these are path-containment bypasses.

Research (window 2026-10-24 to 2026-11-07)

Local scan

Containment checks in actions/setup/js are inconsistent. Safe ones append path.sep (e.g. merge_remote_agent_github_folder.cjs, find_repo_checkout.cjs); others such as engine_log_parser.cjs and push_repo_memory.cjs rely on a trailing separator only by construction. The rule fires only on provable bare path values, so false-positive risk is low; root + path.sep and literal prefixes are accepted.

Validation (from eslint-factory)

  • npm ci: ok
  • npm run build: ok
  • npm test -- src/rules/no-path-startswith-without-separator.test.ts: 2 passed
  • npm run lint:setup-js: exit 0, 0 errors, 1116 warnings (rule enabled as warn)

Registered in src/index.ts, enabled in eslint.config.cjs, documented in README.

Generated by ESLint Miner · copilot · auto (Claude Sonnet 5.5) · ~38 AIC · ⌖ ~1 AIC · ⊞ 10.3K · ◷
Claim finished

  • expires on Nov 13, 2026, 7:32 PM UTC-08:00

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The rule incorrectly flags separator-terminated prefixes, and its containment guidance can accept paths outside the intended root on another Windows drive.

2 open issues
What changed in this PR

Adds a custom ESLint rule to detect path-containment checks that use bare directory prefixes, extending lint coverage for gh-aw’s setup JavaScript.

Changes:

  • Detects startsWith() checks against path.resolve(), path.join(), and path.normalize() results, directly or through single-assignment variables.
  • Adds valid and invalid rule test cases.
  • Registers the rule, enables it as a warning, and documents its usage.
File Description
eslint-factory/​src/​rules/​no-path-startswith-without-separator.ts Implements path-prefix detection and remediation guidance.
eslint-factory/​src/​rules/​no-path-startswith-without-separator.test.ts Tests accepted patterns, reported patterns, and the documentation URL.
eslint-factory/​src/​index.ts Registers the new rule in the plugin.
eslint-factory/​README.md Documents the rule and recommended alternatives.
eslint-factory/​eslint.config.cjs Enables the rule at warning level.

Review effort: Balanced (auto)

schema: [],
messages: {
noBarePathPrefix:
"startsWith() with a bare directory path also matches sibling directories (e.g. /work/repo-evil starts with /work/repo). Compare against `root + path.sep` (and allow `=== root` separately) or use path.relative() and reject results starting with '..'.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Updated the diagnostic to recommend rejecting path.isAbsolute(relative) as well as relative === '..' and relative.startsWith('..' + path.sep). Fix committed as 2154ccd.

node.callee.object.type === "Identifier" &&
node.callee.object.name === "path" &&
node.callee.property.type === "Identifier" &&
PATH_METHODS.has(node.callee.property.name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The matcher now exempts separator-terminated path.join() and path.normalize() results, including direct calls and single-assignment variables; path.resolve() remains flagged. Regression tests cover both forms. Fix committed as 2154ccd.

@pelikhan
pelikhan marked this pull request as ready for review November 7, 2026 04:27
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #75594

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

🔎 PR Code Quality Reviewer is reviewing code quality for this pull request...

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Design Decision Gate 🏗️

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Design Decision Gate 🏗️ · routed: gpt56 max · ~1 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Test Quality Sentinel completed test quality analysis.

Warning

Threat detection engine error

Threat detection could not complete its analysis due to a tooling error. This is not a security finding.

What happened

The threat detection results could not be parsed.

Review the workflow run logs to troubleshoot the error.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ⊞ 6.3K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What this change does: This change adds an ESLint rule that flags startsWith() containment checks against bare path.resolve(), path.join(), and path.normalize() results. It registers and documents the rule and adds focused direct and alias tests.

Should fix:

  1. Duplicate scope resolution (eslint-factory/src/rules/no-path-startswith-without-separator.ts:43-55)

    • What this is: The rule resolves an identifier alias before checking its initializer.
    • Problem: The repository already uses ASTUtils.findVariable(sourceCode.getScope(node), node) for this exact scope-chain lookup (for example, no-dynamic-string-replacement.ts), so this duplicates scope-resolution logic for a one-alias rule.
    • Fix: Import ASTUtils and use that helper, keeping the existing single-definition and write checks.
    • If we skip it: Future scope-resolution fixes must be duplicated here.

Verdict: fix 1 first.
Lean: -8 lines possible.

Generated by ✂️ Ponytail Reviewer for #75594 · codex · routed: gpt56 max · ~3 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again

if (node.type !== "Identifier") {
return false;
}
let scope: ReturnType<typeof sourceCode.getScope> | null = sourceCode.getScope(node);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What this is: This loop resolves the identifier alias before checking its initializer. Problem: The repository already uses ASTUtils.findVariable(sourceCode.getScope(node), node) for this exact scope-chain lookup (for example, no-dynamic-string-replacement.ts), so this duplicates scope-resolution logic for a one-alias rule. Fix: Import ASTUtils and use that helper, keeping the existing single-definition and write checks. If we skip it: Future scope-resolution fixes must be duplicated here.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs, /tdd, and /grill-with-docs. Requesting changes because the rule ships guidance that is wrong for some inputs.

📋 Key Themes & Highlights

Key Themes

  • Incorrect fix advice (blocking): The rule message and README suggest path.relative() with a .. prefix check, which wrongly rejects legitimate names such as ..foo. The root + path.sep advice also breaks filesystem-root paths.
  • Coverage gaps: No test exercises the scope walk when a parameter shadows an outer path variable. Aliased path calls are silently missed.
  • Open threads: The two existing Copilot threads on the path.sep-terminated prefixes (lines 17 and 32) are valid and still apply.

Positive Highlights

  • ✅ Clean isBarePathValue helper with single-assignment checks that limit false positives
  • ✅ Uses context.sourceCode and follows the sibling-rule test layout
  • ✅ Registration in index.ts, eslint.config.cjs, and the README is complete

Limitation

I could not run the rule's tests: npm ci failed on a registry TLS error in this environment, so these findings come from reading the diff and checking Node path behaviour directly.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~6 AIC · ⌖ ~1 AIC · ⊞ 5.4K
Comment /matt to run again

node.callee.type === "MemberExpression" &&
!node.callee.computed &&
node.callee.object.type === "Identifier" &&
node.callee.object.name === "path" &&

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/tdd] isPathCall only matches the bare identifier path. Aliases such as nodePath.resolve(...), path.posix.resolve(...), and destructured resolve calls are silently missed, which is a false negative. Either widen the match or document the limit in the README so authors do not assume full coverage.

@copilot please address this.

Comment thread eslint-factory/README.md Outdated

### `no-path-startswith-without-separator`

Disallow `value.startsWith(root)` where `root` is a bare `path.resolve()`/`path.join()`/`path.normalize()` result (directly or via a single-assignment variable). `/work/repo-evil` passes a `startsWith("/work/repo")` check. Compare against `root + path.sep` (plus `=== root`) or use `path.relative()` instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/grill-with-docs] The advice root + path.sep is wrong for the filesystem root. path.resolve(/) is already /, so the suggested check becomes a startsWith against //, which rejects every absolute path. Document the fix as: append path.sep only when root does not already end with it.

💡 Impact

The failure is fail-closed, so this is not a security hole. It still breaks valid callers, and the same wording appears in the rule message.

@copilot please address this.

schema: [],
messages: {
noBarePathPrefix:
"startsWith() with a bare directory path also matches sibling directories (e.g. /work/repo-evil starts with /work/repo). Compare against `root + path.sep` (and allow `=== root` separately) or use path.relative() and reject results starting with '..'.",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/diagnosing-bugs] The alternative suggested here is unsafe for ..-prefixed names. path.relative(/work/repo, /work/repo/..foo/x) returns ..foo/x, so rejecting any result that starts with .. wrongly blocks a legitimate file. Check the path segment instead: rel === ".." || rel.startsWith(".." + path.sep) || path.isAbsolute(rel).

💡 Verified behaviour

Checked with Node: the result for that example is ..foo/x. The path.isAbsolute check also covers the Windows cross-drive case raised in the open thread.

@copilot please address this.

`const root = path.resolve(base); if (dest.startsWith(root + path.sep)) {}`,
"const root = path.resolve(base); if (dest.startsWith(`${root}${path.sep}`)) {}",
`if (path.resolve(target).startsWith("/tmp/gh-aw/")) {}`,
`function f(root) { return file.startsWith(root); }`,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/tdd] Add a shadowing case here. An outer const root = path.resolve(...) that an inner parameter shadows should stay valid. Nothing covers the scope walk in isBarePathValue yet.

💡 Suggested test
`const root = path.resolve(base); function f(root) { return file.startsWith(root); }`,

@copilot please address this.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Fix failing check conclusion (FAILURE): https://github.com/github/gh-aw/actions/runs/42338575398/job/128302557511.

Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI.

Sous-chef requested-head: da7531a
Sous-chef requested-work: 51e2287c3d1ee41b7e13769862add61dcd292a623cf943abc5968c984e246bcf
Sous-chef requested-state: 7592ab2258e251f93889b0e4e4f8e15061a5bceb38c41d1f62f527f937e606b7

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~9 AIC · ⌖ ~8 AIC · ⊞ 1.2K · ◷
Comment /souschef to run again

Copilot AI commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@copilot

Copilot assignment requested for the following outstanding work:...

Sous-chef requested-head: da7531a
Sous-chef requested-work: 51e2287c3d1ee41b7e13769862add61dcd292a623cf943abc5968c984e246bcf
Sous-chef requested-state: 7592ab2258e251f93889b0e4e4f8e15061a5bceb38c41d1f62f527f937e606b7

Copilot AI and others added 2 commits November 7, 2026 05:08
…startswith-without-separator-7d0e882b21d2ac1d

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI requested a review from gh-aw-bot November 7, 2026 05:19
@pelikhan
pelikhan merged commit 7f62a1a into main Nov 7, 2026
20 checks passed
@pelikhan
pelikhan deleted the eslint-miner/no-path-startswith-without-separator-7d0e882b21d2ac1d branch November 7, 2026 05:23
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v1.2.2

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants