Skip to content

Commit b4a51d2

Browse files
peppescgkantord
andcommitted
Semgrep pre-commit hook
Co-authored-by: Dániel Kántor <[email protected]>
1 parent 1dc6e7e commit b4a51d2

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests:
2+
- name: "Should have Semgrep pre-commit hook configured"
3+
def: {}
4+
params: {}
5+
expect: "pass"
6+
git:
7+
repo_base: correct
8+
- name: "Should fail Semgrep pre-commit hook is not configured"
9+
def: {}
10+
params: {}
11+
expect: "fail"
12+
git:
13+
repo_base: misconfigured
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
args: ['--maxkb=600']
10+
- repo: https://github.com/semgrep/pre-commit
11+
rev: 'v1.101.0'
12+
hooks:
13+
- id: semgrep
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
args: ['--maxkb=600']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
version: v1
3+
release_phase: alpha
4+
type: rule-type
5+
name: semgrep_secrets_scanning
6+
display_name: Enable Semgrep Pre-commit hooks for detecting secrets
7+
short_failure_message: Semgrep Pre-commit hook is not configured for the repository
8+
severity:
9+
value: medium
10+
context: {}
11+
description: |
12+
Verifies that Semgrep Pre-commit hook is configured via a GitHub action for the repository, and remediate
13+
guidance: |
14+
Likewise, you can configure a hook to run a semgrep scan with the semgrep hook. As an example, the following configuration would scan the files to be committed with a specified config, skipping files with unknown extensions.
15+
For more information, see the [Semgrep Pre-commit](https://semgrep.dev/docs/secure-guardrails/secure-guardrails-in-semgrep) documentation.
16+
def:
17+
in_entity: repository
18+
rule_schema:
19+
type: object
20+
properties: {}
21+
ingest:
22+
type: git
23+
git: {}
24+
eval:
25+
type: rego
26+
rego:
27+
type: deny-by-default
28+
def: |
29+
package minder
30+
import future.keywords.if
31+
import future.keywords.every
32+
33+
default message := "Semgrep pre-commit hook is not configured for the repository"
34+
default allow := false
35+
36+
37+
# pre-commit hook
38+
precommit := file.read(".pre-commit-config.yaml")
39+
40+
parsed_data := parse_yaml(precommit)
41+
42+
allow if {
43+
some repo_id, hook_id
44+
repo_data := parsed_data.repos[repo_id]
45+
endswith(repo_data["repo"], "https://github.com/semgrep/pre-commit")
46+
semgrep_hooks = repo_data["hooks"]
47+
semgrep_hooks[hook_id].id == "semgrep"
48+
}
49+
50+
message := "" if allow
51+
alert:
52+
type: security_advisory
53+
security_advisory: {}

0 commit comments

Comments
 (0)