fix: add output encoding in hook-before-edit.mjs#313
Conversation
Automated security fix generated by OrbisAI Security
User input from data entry functions flows into application without proper sanitization or output encoding, creating cross-site scripting vulnerabilities
Greptile SummaryThis PR hardens
Confidence Score: 5/5The hook source and its generated copy are updated identically; the main()-guard pattern is standard and safe for direct invocation. Both skill/ and plugin/ receive the same changes, the test file uses the correct node:test runner and properly imported ESM exports, and the entry-point guard follows the widely-used process.argv[1] === fileURLToPath(import.meta.url) idiom without risk of silently suppressing hook execution in the expected deployment context. tests/invariant_hook-before-edit.test.mjs — the import points at the generated artifact rather than the canonical source; fix is a one-line path change. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Hook invoked by agent harness] --> B{Entry-point guard passes?}
B -- Yes --> C[main called]
B -- No --> D[Module imported for testing only]
C --> E[proposedFilePath]
E --> F{candidate has angle bracket or quote?}
F -- Yes --> G[return empty string - allow skip]
F -- No --> H[path.resolve - normal hook flow]
D --> I[proposedFilePath and shellHereDocContent called from tests]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[Hook invoked by agent harness] --> B{Entry-point guard passes?}
B -- Yes --> C[main called]
B -- No --> D[Module imported for testing only]
C --> E[proposedFilePath]
E --> F{candidate has angle bracket or quote?}
F -- Yes --> G[return empty string - allow skip]
F -- No --> H[path.resolve - normal hook flow]
D --> I[proposedFilePath and shellHereDocContent called from tests]
Reviews (3): Last reviewed commit: "Apply code changes: @orbisai0security ca..." | Re-trigger Greptile |
…rt heredoc refactor, fix test - Remove `'` from proposedFilePath character-rejection regex: single quotes are valid in filenames and the original inclusion was an over-restriction - Revert shellHereDocContent to the original regex approach; the indexOf replacement lost the line-boundary anchor and would falsely match a marker name appearing as a prefix in the body (e.g. EOFfoo with marker EOF) - Rewrite test from broken CJS require to ESM node:test, add single-quote acceptance case, add heredoc substring regression case, wire into core suite Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
| import { | ||
| proposedFilePath, | ||
| shellHereDocContent, | ||
| } from '../plugin/skills/impeccable/scripts/hook-before-edit.mjs'; |
There was a problem hiding this comment.
Test registered in CI will break after next
build:release
The test imports proposedFilePath and shellHereDocContent as named exports from ../plugin/skills/impeccable/scripts/hook-before-edit.mjs. The export statement was only added to the generated artifact in plugin/, not to the canonical source at skill/scripts/hook-before-edit.mjs. When sync-generated-output.yml next runs bun run build:release, it will regenerate plugin/skills/impeccable/scripts/hook-before-edit.mjs from the source without the export, causing this test to fail with SyntaxError: The requested module … does not provide an export named 'proposedFilePath' — breaking the CI suite that scripts/test-suites.mjs now includes it in.
Context Used: AGENTS.md (source)
|
I analyzed your request and ran the commands, but no file changes were produced. This can happen when:
Could you provide more specific instructions about which files and lines to change? |
|
✅ Changes Applied I've updated the code based on your feedback: Addressing the code review feedback with two targeted fixes:
The Files modified:
The changes have been pushed to this PR branch. Please review! |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit eaf0f45. Configure here.
| } | ||
| done({ permission: 'allow' }); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Broken hook entry guard
High Severity
The new process.argv[1] === fileURLToPath(import.meta.url) guard usually fails when the hook is started with a relative script path, so main() never runs, stdin is never handled, and no hook JSON is written.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit eaf0f45. Configure here.
There was a problem hiding this comment.
@orbisai0security can you address code review comments?
|
I analyzed your request and ran the commands, but no file changes were produced. This can happen when:
Could you provide more specific instructions about which files and lines to change? |


Summary
Fix high severity security issue in
plugin/skills/impeccable/scripts/hook-before-edit.mjs.Vulnerability
V-005plugin/skills/impeccable/scripts/hook-before-edit.mjs:70Description: User input from data entry functions flows into application without proper sanitization or output encoding, creating cross-site scripting vulnerabilities.
Evidence
Exploitation scenario: Attacker injects malicious JavaScript payloads into toolInput or onInlineInput functions, which execute in victim's browser when unsanitized input is rendered.
Scanner confirmation: multi_agent_ai rule
V-005flagged this pattern.Production code: This file is in the production codebase, not test-only code.
Threat Model Context
This is a Node.js library - vulnerabilities affect downstream consumers who use this package.
Changes
plugin/skills/impeccable/scripts/hook-before-edit.mjsVerification
Security Invariant
Regression test
This test guards against regressions — it's useful independent of the code change above.
Automated security fix by OrbisAI Security
Note
Medium Risk
Touches security-sensitive path parsing on the write gate; the change is small and covered by new invariant tests, but incorrect filtering could skip scans or break legitimate paths with quotes.
Overview
Hardens the Cursor preToolUse write gate in
hook-before-edit.mjs(plugin and skill copies) so attacker-controlledfile_path/ shell-derived paths cannot carry HTML-like payloads into downstream handling.proposedFilePathnow returns an empty path when the candidate contains<,>, or", which makes the hook allow the tool withskipped: 'no-file-path'instead of resolving a dangerous string.proposedFilePathandshellHereDocContentare exported, andmain()only runs when the script is executed directly (viafileURLToPath(import.meta.url)), so unit tests can import helpers without starting the hook.Adds
tests/invariant_hook-before-edit.test.mjscovering blocked XSS-style path inputs, normal paths, and heredoc parsing edge cases, and registers it in the core test suite inscripts/test-suites.mjs.Reviewed by Cursor Bugbot for commit eaf0f45. Bugbot is set up for automated code reviews on this repo. Configure here.