Class RegexMatcher

java.lang.Object
com.tnsai.quality.security.harness.RegexMatcher
All Implemented Interfaces:
MatcherSpi

public class RegexMatcher extends Object implements MatcherSpi
Generic regex-based MatcherSpi (TNS-291).

Each built-in matcher is an instance of this class with its own set of patterns, file-extension filter, and default severity. Custom matchers can either extend this class or implement MatcherSpi directly (e.g. for AST-based or import-graph-based checks that regex can't express).

Hits are reported with line numbers derived from the byte offset of the regex match against the content string.

Since:
0.10.0 (TNS-291)
  • Constructor Details

    • RegexMatcher

      public RegexMatcher(String id, String cwe, Severity severity, String description, List<Pattern> patterns, Set<String> extensions)
      Parameters:
      id - stable matcher id
      cwe - CWE id
      severity - default severity (used when no agent revisits the hit)
      description - short summary of what the matcher looks for
      patterns - regex patterns; each find() produces one MatcherSpi.Hit
      extensions - file extensions (with leading dot, e.g. ".java") this matcher applies to. Empty = match every file.
  • Method Details

    • id

      public String id()
      Description copied from interface: MatcherSpi
      Stable id, e.g. "sql-injection".
      Specified by:
      id in interface MatcherSpi
    • cwe

      public String cwe()
      Description copied from interface: MatcherSpi
      CWE id this matcher targets, e.g. "CWE-89".
      Specified by:
      cwe in interface MatcherSpi
    • defaultSeverity

      public Severity defaultSeverity()
      Description copied from interface: MatcherSpi
      Default severity assigned when this matcher fires alone (no agent).
      Specified by:
      defaultSeverity in interface MatcherSpi
    • description

      public String description()
      Description copied from interface: MatcherSpi
      Human-readable description of what this matcher looks for.
      Specified by:
      description in interface MatcherSpi
    • scan

      public List<MatcherSpi.Hit> scan(Path file, String content)
      Description copied from interface: MatcherSpi
      Scan content and return the locations where the matcher found a candidate. Returning an empty list means the file is clean w.r.t. this matcher.
      Specified by:
      scan in interface MatcherSpi
      Parameters:
      file - relative path inside the project — only used for language gating (e.g. skip non-Java files)
      content - full file content as UTF-8