Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

named match group in metavariable-regex causes duplication of matches #10209

Open
2 of 3 tasks
jagprog5 opened this issue May 6, 2024 · 0 comments
Open
2 of 3 tasks

Comments

@jagprog5
Copy link

jagprog5 commented May 6, 2024

Using a metavariable-regex with a named match group erroneously duplicates reported matches.

semgrep v1.70.0 via playground.

Rule:

rules:
  - id: id-here
    languages:
      - csharp
    severity: WARNING
    message: CipherMode $MODE detected
    patterns:
      - metavariable-regex:
          metavariable: $METHOD
          regex: \A(?:Encrypt|Try(?:Encrypt|Decrypt))(?P<MODE>.+)\Z
      - pattern: (System.Security.Cryptography.SymmetricAlgorithm $OBJ).$METHOD(...)

Test code:

using System.Security.Cryptography;

class Program {
    static void Main() {
        SymmetricAlgorithm sym = Aes.Create();
        ReadOnlySpan<byte> read_only_span = new ReadOnlySpan<byte>();
        sym.EncryptCbc(read_only_span, read_only_span);
    }
}

Output:

Line 7: CipherMode $MODE detected
Line 7: CipherMode Cbc detected

Expected Output:

Line 7: CipherMode Cbc detected

What is the priority of the bug to you?

  • P0: blocking your adoption of Semgrep or workflow
  • P1: important to fix or quite annoying
  • P2: regular bug that should get fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant