Skip to content

fix(rules): hardcoded-secret false-positive filter drops real secrets when the line has a trailing comment containing ':' #603

Closed

Description

@ajianaz

Problem

is_false_positive_secret (src/engine/rules/builtin.rs) looks for the first ':' anywhere in the line and, if the text after it is a bare identifier, treats the match as an object-shorthand false positive. A real secret followed by a comment is therefore dropped:

const api_password = "hunter2hunter2xx"; // note: fix later

Reproduced on v0.16.1 with cora scan (LLM unreachable): the same line without the comment is flagged, with the comment it is not. It also means any line carrying a cora-ignore: <rule> marker never produces a scanner finding, so the alias recorded by #597 for the dedup edge case never gets used in practice (the marker still works because the scanner finding is already gone, but an LLM issue on that line with its own title is not suppressed by a marker naming the scanner rule).

Direction

Only consider a ':' that is outside string literals and outside a trailing comment (or strip trailing comments, //, #, --, /* */, before the shorthand check), and require that the match itself sits in the object-literal shape. Add tests: secret + trailing comment with a colon is still flagged; { app_secret: formAppSecret } still is not.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions