Skip to content

Add support for matching the lack of a pattern #126

Description

@hrideshmg

Hi, I'm not sure if this is currently possible, but it would be useful to check for patterns that should exist, in addition to detecting patterns that should not exist. This could maybe be implemented as a configuration option in the YAML file?

Certain security best practices recommend the presence of specific statements. For example, The OWASP Cheat Sheet suggests using a USER directive in Dockerfiles to prevent privilege escalation attacks. However, I don’t see a way to enforce this check using the current format.

Activity

  1. sanket-deepsource commented on Feb 25, 2025

    @sanket-deepsource
    Contributor

    This is an interesting idea. Yes, this isn't possible in our current YAML format (or the checker API overall, for that matter) since the core design is to detect an anti-pattern, not an expected pattern. I'm sure there could be other scenarios where we'd like to assert a pattern.

    One way of implementing this could be a global flag on the checker that essentially inverts the detection — it will alert if the pattern (using our existing framework) isn't detected.

    @sourya-deepsource would love your thoughts on this.

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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions