Skip to content

fix(validator): reject findings inside JS block comments - #40

Open
harshitgavita-07 wants to merge 1 commit into
openhackai:mainfrom
harshitgavita-07:fix-static-validator-block-comments
Open

harshitgavita-07 wants to merge 1 commit into
openhackai:mainfrom
harshitgavita-07:fix-static-validator-block-comments

Conversation

@harshitgavita-07

Copy link
Copy Markdown

Problem

openhack/static_validator.py is the deterministic pre-validator whose stated job (module docstring) is to filter out findings that are provably wrong before the LLM validator runs — including "Is the pattern in a comment or string literal, not actual code?"

For JS/TS files, _is_comment_line only detects // line comments. _JS_BLOCK_COMMENT_START / _JS_BLOCK_COMMENT_END are defined at module level but never used, so a finding whose reported line sits inside a /* ... */ block comment passes Layer A (the line is not recognized as a comment, and the sink window does contain the claimed pattern) and can also pass the tree-sitter layer, since the comment text inside an enclosing function still matches user-input accessor patterns. A "provably wrong" finding therefore survives both layers and consumes LLM validation budget.

Reproduction

function handler(req, res) {
  /*
   * Legacy debug path, disabled:
   * eval(req.query.code)
   */
  const q = sanitize(req.query.code);
  res.send(q);
}

A finding {file_path, line_number: 4, category: "rce"} (the eval line, inside the block comment) is currently accepted by validate_finding_basic and by run_static_validation.

Fix

Add _is_in_block_comment(lines, line_number), which tracks /* / */ state across the lines preceding the reported line and also treats a target line that itself opens a block comment as commented. validate_finding_basic rejects the finding when the reported line is inside a block comment (non-Python files), using the previously unused module-level regexes. Behavior for // comments, Python comments/docstrings, and real sinks after a closed comment block is unchanged.

Tests

New tests/test_static_validator.py (5 tests, all failing-before/passing-after where applicable):

  • finding inside a multi-line block comment is rejected
  • finding on a single-line /* ... */ comment is rejected
  • end-to-end: run_static_validation drops a block-comment finding
  • control: a real sink after a closed block comment still passes
  • control: // line comments are still rejected

Full suite: 516 passed (511 existing + 5 new).

The static pre-validator's Layer A checks whether a reported sink sits in
a comment rather than actual code, but _is_comment_line only handled //
line comments for JS/TS. _JS_BLOCK_COMMENT_START/END were defined but
never used, so a finding pointing inside a /* ... */ block comment passed
both validation layers even though the sink is provably not live code.

Track block-comment state up to the reported line and reject findings
whose target line opens or sits inside a block comment. Adds
tests/test_static_validator.py (5 tests: multi-line block comment,
single-line block comment, pipeline end-to-end, plus controls showing
real sinks after a closed comment and // line comments behave as before).
@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 1/5

[Medium impact] The change affects which findings continue through one validation workflow.

Do not merge until the block-comment check stops dropping findings on executable code.

Fix All in CodexFindings

  1. P1 Security Strings can hide real findings ▶
  2. P1 Security Code after comments gets ignored ▶
Fix with agent prompt
### Issue 1
openhack/static_validator.py:204-208
The scan treats `/*` inside strings and `//` comments as a real comment opening. For example, `const pattern = "/*";` followed by `eval(req.query.code);` makes the executable `eval` line fail `validate_finding_basic`. `run_static_validation` then drops that finding from `passed`. Track strings and line comments before changing block-comment state.

**How this was verified:** The preceding-line scan uses an unconditional `raw.find("/*", i)`, and the new rejection gate removes matching findings before further checks.

### Issue 2
openhack/static_validator.py:209-216
The target line is rejected without checking for executable code after `*/`. Both `/* note */ eval(req.query.code);` and `*/ eval(req.query.code);` after an earlier comment opening contain executable calls, but this helper returns `True` for both. That drops real security findings. Inspect the target line through its closing delimiter, and keep findings when executable code remains.

**How this was verified:** The helper returns immediately when the preceding lines leave a comment open; otherwise it rejects any target line starting with `/*`, without checking where that comment ends.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds block-comment checks to validate_finding_basic and five tests.

  • The validator filters findings reported inside block comments.

Reviews (1) · Last reviewed commit: "fix(validator): reject findings inside J..." · Reviewed by Greptile

Comment on lines +204 to +208
start = raw.find("/*", i)
if start == -1:
break
in_block = True
i = start + 2

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 security Strings can hide real findings

The scan treats /* inside strings and // comments as a real comment opening. For example, const pattern = "/*"; followed by eval(req.query.code); makes the executable eval line fail validate_finding_basic. run_static_validation then drops that finding from passed. Track strings and line comments before changing block-comment state.

How this was verified: The preceding-line scan uses an unconditional raw.find("/*", i), and the new rejection gate removes matching findings before further checks.

Prompt To Fix With AI
This is a comment left during a code review.
Path: openhack/static_validator.py
Line: 204-208

Comment:
**Strings can hide real findings**

The scan treats `/*` inside strings and `//` comments as a real comment opening. For example, `const pattern = "/*";` followed by `eval(req.query.code);` makes the executable `eval` line fail `validate_finding_basic`. `run_static_validation` then drops that finding from `passed`. Track strings and line comments before changing block-comment state.

**How this was verified:** The preceding-line scan uses an unconditional `raw.find("/*", i)`, and the new rejection gate removes matching findings before further checks.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex Fix in Claude Code Fix in Cursor Fix in Conductor

Comment on lines +209 to +216
if in_block:
return True
if 0 < line_number <= len(lines):
target = lines[line_number - 1]
# Strip line-number prefix if present (from read_file format)
if "\t" in target:
target = target.split("\t", 1)[1]
return bool(_JS_BLOCK_COMMENT_START.match(target.strip()))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 security Code after comments gets ignored

The target line is rejected without checking for executable code after */. Both /* note */ eval(req.query.code); and */ eval(req.query.code); after an earlier comment opening contain executable calls, but this helper returns True for both. That drops real security findings. Inspect the target line through its closing delimiter, and keep findings when executable code remains.

How this was verified: The helper returns immediately when the preceding lines leave a comment open; otherwise it rejects any target line starting with /*, without checking where that comment ends.

Prompt To Fix With AI
This is a comment left during a code review.
Path: openhack/static_validator.py
Line: 209-216

Comment:
**Code after comments gets ignored**

The target line is rejected without checking for executable code after `*/`. Both `/* note */ eval(req.query.code);` and `*/ eval(req.query.code);` after an earlier comment opening contain executable calls, but this helper returns `True` for both. That drops real security findings. Inspect the target line through its closing delimiter, and keep findings when executable code remains.

**How this was verified:** The helper returns immediately when the preceding lines leave a comment open; otherwise it rejects any target line starting with `/*`, without checking where that comment ends.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex Fix in Claude Code Fix in Cursor Fix in Conductor

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.

1 participant