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

feat: support multiple required detections #1659

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

elsapet
Copy link
Contributor

@elsapet elsapet commented Jul 29, 2024

Description

Add support for multiple required detections (relevant for rules triggered by absence of detections).
Ordering of required detections allows us to target which one is displayed in report output; namely, the first one.

For example, the following rule pattern (extract)

trigger:
  match_on: absence
  required_detections:
    - csharp_lang_missing_authorization_controller_class
    - csharp_lang_missing_authorization_aspnet_mvc
auxiliary:
  - id: csharp_lang_missing_authorization_aspnet_mvc
    patterns:
      - using Microsoft.AspNetCore.Mvc;
  - id: csharp_lang_missing_authorization_controller_class
    patterns:
      - |
        $<...>public class $<...>$<_>$<...> : Controller {}

will yield the below report output (that is, it displays the public class X : Controller line and not the using X; line)

MEDIUM: Missing authorization for controller class [CWE-862]
To ignore this finding, run: bearer ignore add 638dcc604dfb349a2e801bf63dc612a3_0

File: /Users/elsapet/cycode/backend-team/sast/rules/tests/csharp/lang/missing_authorization/testdata/main.cs:6

 6     [Route("api/[controller]")]
 7     public class FooController : Controller
 8     {
           ...omitted (buffer value 3)
 10         {
 11         }
 12     }

Note, existing required_detection is still supported.

Checklist

If this is your first time contributing please sign the CLA

  • I've added test coverage that shows my fix or feature works as expected.
  • I've updated or added documentation if required.

@elsapet elsapet requested a review from didroe July 29, 2024 11:49
@elsapet elsapet merged commit 20ef042 into main Jul 30, 2024
8 checks passed
@elsapet elsapet deleted the feat/support-multiple-required-detections branch July 30, 2024 07:25
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.

2 participants