Skip to content

Commit 3e1503c

Browse files
committed
feat: Add extra scan results information
1 parent 67aec49 commit 3e1503c

26 files changed

+801
-1646
lines changed

ggshield/verticals/secret/secret_scan_collection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ class Secret:
8383
Named Secret since we are dropping other kind of policy breaks.
8484
"""
8585

86-
detector: str
86+
detector: str # Detector display name
87+
detector_name: str
88+
detector_group_name: str
89+
documentation_url: Optional[str]
8790
validity: str
8891
known_secret: bool
8992
incident_url: Optional[str]
@@ -187,6 +190,9 @@ def from_scan_result(
187190
known_secret=policy_break.known_secret,
188191
incident_url=policy_break.incident_url,
189192
detector=policy_break.break_type,
193+
detector_name=policy_break.detector_name,
194+
detector_group_name=policy_break.detector_group_name,
195+
documentation_url=policy_break.documentation_url,
190196
matches=[
191197
ExtendedMatch.from_match(match, lines, result.is_on_patch)
192198
for match in policy_break.matches

pdm.lock

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies = [
4141
"marshmallow~=3.18.0",
4242
"marshmallow-dataclass~=8.5.8",
4343
"oauthlib~=3.2.1",
44-
"pygitguardian~=1.20.0",
44+
"pygitguardian @ git+https://github.com/GitGuardian/py-gitguardian.git@933318c6a3fc7a5cce1fdbb663b4e90a2b7992a2",
4545
"pyjwt~=2.6.0",
4646
"python-dotenv~=0.21.0",
4747
"pyyaml~=6.0.1",

tests/factories.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class Meta:
6060

6161
break_type = factory.lazy_attribute(lambda obj: random.choice(DETECTOR_NAMES))
6262
policy = "Secrets detection"
63+
detector_name = factory.lazy_attribute(lambda obj: obj.break_type)
64+
detector_group_name = factory.lazy_attribute(lambda obj: obj.break_type)
65+
documentation_url = None
6366
validity = "valid"
6467
known_secret = False
6568
incident_url = None
@@ -95,6 +98,9 @@ class Meta:
9598
model = Secret
9699

97100
detector = factory.lazy_attribute(lambda obj: random.choice(DETECTOR_NAMES))
101+
detector_name = factory.lazy_attribute(lambda obj: obj.detector)
102+
detector_group_name = factory.lazy_attribute(lambda obj: obj.detector)
103+
documentation_url = None
98104
validity = "valid"
99105
known_secret = True
100106
incident_url = None

tests/unit/cassettes/multiline_secret.yaml

Lines changed: 38 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -9,151 +9,75 @@ interactions:
99
Connection:
1010
- keep-alive
1111
User-Agent:
12-
- pygitguardian/1.15.2 (Linux;py3.10.12)
12+
- pygitguardian/1.20.0 (Linux;py3.11.10)
1313
method: GET
1414
uri: https://api.gitguardian.com/v1/metadata
1515
response:
1616
body:
1717
string:
18-
'{"version":"v2.87.2","preferences":{"marketplaces__aws_product_url":"http://aws.amazon.com/marketplace/pp/prodview-mrmulzykamba6","on_premise__restrict_signup":true,"on_premise__is_email_server_configured":true,"on_premise__default_sso_config_api_id":null,"onboarding__segmentation_v1_enabled":true,"general__maximum_payload_size":26214400,"general__mutual_tls_mode":"disabled","general__signup_enabled":true},"secret_scan_preferences":{"maximum_documents_per_scan":20,"maximum_document_size":1048576},"remediation_messages":{"pre_commit":">
18+
'{"version":"v2.193.0","preferences":{"marketplaces__aws_product_url":"http://aws.amazon.com/marketplace/pp/prodview-mrmulzykamba6","on_premise__restrict_signup":true,"on_premise__is_email_server_configured":true,"on_premise__default_sso_config_api_id":null,"on_premise__default_sso_config_force_sso":null,"onboarding__segmentation_v1_enabled":true,"general__maximum_payload_size":26214400,"general__mutual_tls_mode":"disabled","general__signup_enabled":true},"secret_scan_preferences":{"maximum_documents_per_scan":20,"maximum_document_size":1048576},"remediation_messages":{"pre_commit":">
1919
How to remediate\n\n Since the secret was detected before the commit was
2020
made:\n 1. replace the secret with its reference (e.g. environment variable).\n 2.
21-
commit again.\n\n> [To apply with caution] If you want to bypass ggshield
22-
(false positive or other reason), run:\n - if you use the pre-commit framework:\n\n SKIP=ggshield
23-
git commit -m \"<your message>","pre_push":"> How to remediate\n\n Since
21+
commit again.\n\n> [Apply with caution] If you want to bypass ggshield (false
22+
positive or other reason), run:\n - if you use the pre-commit framework:\n\n SKIP=ggshield
23+
git commit -m \"<your message>\"\n ","pre_push":"> How to remediate\n\n Since
2424
the secret was detected before the push BUT after the commit, you need to:\n 1.
2525
rewrite the git history making sure to replace the secret with its reference
2626
(e.g. environment variable).\n 2. push again.\n\n To prevent having to rewrite
2727
git history in the future, setup ggshield as a pre-commit hook:\n https://docs.gitguardian.com/ggshield-docs/integrations/git-hooks/pre-commit\n\n>
28-
[To apply with caution] If you want to bypass ggshield (false positive or
29-
other reason), run:\n - if you use the pre-commit framework:\n\n SKIP=ggshield-push
28+
[Apply with caution] If you want to bypass ggshield (false positive or other
29+
reason), run:\n - if you use the pre-commit framework:\n\n SKIP=ggshield-push
3030
git push","pre_receive":"> How to remediate\n\n A pre-receive hook set server
3131
side prevented you from pushing secrets.\n\n Since the secret was detected
3232
during the push BUT after the commit, you need to:\n 1. rewrite the git history
3333
making sure to replace the secret with its reference (e.g. environment variable).\n 2.
3434
push again.\n\n To prevent having to rewrite git history in the future, setup
3535
ggshield as a pre-commit hook:\n https://docs.gitguardian.com/ggshield-docs/integrations/git-hooks/pre-commit\n\n>
36-
[To apply with caution] If you want to bypass ggshield (false positive or
37-
other reason), run:\n\n git push -o breakglass"}}'
36+
[Apply with caution] If you want to bypass ggshield (false positive or other
37+
reason), run:\n\n git push -o breakglass"}}'
3838
headers:
3939
access-control-expose-headers:
4040
- X-App-Version
4141
allow:
4242
- GET, HEAD, OPTIONS
4343
content-length:
44-
- '2150'
44+
- '2198'
4545
content-type:
4646
- application/json
4747
cross-origin-opener-policy:
4848
- same-origin
4949
date:
50-
- Mon, 12 Aug 2024 09:19:09 GMT
50+
- Tue, 22 Apr 2025 13:27:58 GMT
5151
referrer-policy:
5252
- strict-origin-when-cross-origin
5353
server:
5454
- istio-envoy
5555
strict-transport-security:
5656
- max-age=31536000; includeSubDomains
57+
transfer-encoding:
58+
- chunked
5759
vary:
5860
- Accept-Encoding,Cookie
5961
x-app-version:
60-
- v2.87.2
62+
- v2.193.0
6163
x-content-type-options:
6264
- nosniff
6365
- nosniff
6466
x-envoy-upstream-service-time:
65-
- '25'
67+
- '64'
6668
x-frame-options:
6769
- DENY
6870
- SAMEORIGIN
6971
x-secrets-engine-version:
70-
- 2.117.0
72+
- 2.136.1
7173
x-xss-protection:
7274
- 1; mode=block
7375
status:
7476
code: 200
7577
message: OK
7678
- request:
7779
body:
78-
'[{"filename": "file", "document": "-----BEGIN RSA PRIVATE KEY-----\nMIIBOgIBAAJBAIIRkYjxjE3KIZiEc8k4sWWGNsPYRNE0u0bl5oFVApPLm+uXQ/4l\nbKO9LFtMiVPy700oMWLScwAN5OAiqVLMvHUCAwEAAQJANLr8nmEWuV6t2hAwhK5I\nNNmBkEo4M/xFxEtl9J7LKbE2gtNrlCQiJlPP1EMhwAjDOzQcJ3lgFB28dkqH5rMW\nTQIhANrCE7O+wlCKe0WJqQ3lYlHG91XWyGVgfExJwBDsAD9LAiEAmDY5OSsH0n2A\n22tthkAvcN1s66lG+0DztOVJ4QLI2z8CIBPeDGwGpx8pdIicN/5LFuLWbyAcoZaT\nbLaA/DCNPniBAiA0l//bzg+M3srIhm04xzLdR9Vb9IjPRlkvN074zdKDVwIhAKJb\nRF3C+CMFb0wXme/ovcDeM1+3W/UmSHYUW4b3WYq4\n-----END
79-
RSA PRIVATE KEY-----"}]'
80-
headers:
81-
Accept:
82-
- '*/*'
83-
Accept-Encoding:
84-
- gzip, deflate
85-
Connection:
86-
- keep-alive
87-
Content-Length:
88-
- '538'
89-
Content-Type:
90-
- application/json
91-
GGShield-Command-Id:
92-
- 7a6ae986-4f2d-45ff-9a71-91fdd049ef51
93-
GGShield-Command-Path:
94-
- external
95-
GGShield-OS-Name:
96-
- ubuntu
97-
GGShield-OS-Version:
98-
- '22.04'
99-
GGShield-Python-Version:
100-
- 3.10.12
101-
GGShield-Version:
102-
- 1.29.0
103-
User-Agent:
104-
- pygitguardian/1.15.2 (Linux;py3.10.12)
105-
mode:
106-
- path
107-
method: POST
108-
uri: https://api.gitguardian.com/v1/multiscan?ignore_known_secrets=True
109-
response:
110-
body:
111-
string:
112-
'[{"policy_break_count":1,"policies":["File extensions","Filenames","Secrets
113-
detection"],"policy_breaks":[{"type":"RSA Private Key","policy":"Secrets detection","matches":[{"type":"apikey","match":"-----BEGIN
114-
RSA PRIVATE KEY-----\nMIIBOgIBAAJBAIIRkYjxjE3KIZiEc8k4sWWGNsPYRNE0u0bl5oFVApPLm+uXQ/4l\nbKO9LFtMiVPy700oMWLScwAN5OAiqVLMvHUCAwEAAQJANLr8nmEWuV6t2hAwhK5I\nNNmBkEo4M/xFxEtl9J7LKbE2gtNrlCQiJlPP1EMhwAjDOzQcJ3lgFB28dkqH5rMW\nTQIhANrCE7O+wlCKe0WJqQ3lYlHG91XWyGVgfExJwBDsAD9LAiEAmDY5OSsH0n2A\n22tthkAvcN1s66lG+0DztOVJ4QLI2z8CIBPeDGwGpx8pdIicN/5LFuLWbyAcoZaT\nbLaA/DCNPniBAiA0l//bzg+M3srIhm04xzLdR9Vb9IjPRlkvN074zdKDVwIhAKJb\nRF3C+CMFb0wXme/ovcDeM1+3W/UmSHYUW4b3WYq4\n-----END
115-
RSA PRIVATE KEY-----","index_start":0,"index_end":491,"line_start":1,"line_end":9}],"incident_url":"https://dashboard.gitguardian.com/workspace/8/incidents/8137383","known_secret":true,"validity":"no_checker"}]}]'
116-
headers:
117-
access-control-expose-headers:
118-
- X-App-Version
119-
allow:
120-
- POST, OPTIONS
121-
content-length:
122-
- '889'
123-
content-type:
124-
- application/json
125-
cross-origin-opener-policy:
126-
- same-origin
127-
date:
128-
- Mon, 12 Aug 2024 09:19:10 GMT
129-
referrer-policy:
130-
- strict-origin-when-cross-origin
131-
server:
132-
- istio-envoy
133-
strict-transport-security:
134-
- max-age=31536000; includeSubDomains
135-
vary:
136-
- Cookie
137-
x-app-version:
138-
- v2.87.2
139-
x-content-type-options:
140-
- nosniff
141-
- nosniff
142-
x-envoy-upstream-service-time:
143-
- '65'
144-
x-frame-options:
145-
- DENY
146-
- SAMEORIGIN
147-
x-secrets-engine-version:
148-
- 2.117.0
149-
x-xss-protection:
150-
- 1; mode=block
151-
status:
152-
code: 200
153-
message: OK
154-
- request:
155-
body:
156-
'[{"filename": "/tmp/pytest-of-mmillet/pytest-1/test_json_output_for_patch__MU1/file",
80+
'[{"filename": "/tmp/pytest-of-salomevoltz/pytest-8/test_json_output_for_patch__MU0/file",
15781
"document": "-----BEGIN RSA PRIVATE KEY-----\nMIIBOgIBAAJBAIIRkYjxjE3KIZiEc8k4sWWGNsPYRNE0u0bl5oFVApPLm+uXQ/4l\nbKO9LFtMiVPy700oMWLScwAN5OAiqVLMvHUCAwEAAQJANLr8nmEWuV6t2hAwhK5I\nNNmBkEo4M/xFxEtl9J7LKbE2gtNrlCQiJlPP1EMhwAjDOzQcJ3lgFB28dkqH5rMW\nTQIhANrCE7O+wlCKe0WJqQ3lYlHG91XWyGVgfExJwBDsAD9LAiEAmDY5OSsH0n2A\n22tthkAvcN1s66lG+0DztOVJ4QLI2z8CIBPeDGwGpx8pdIicN/5LFuLWbyAcoZaT\nbLaA/DCNPniBAiA0l//bzg+M3srIhm04xzLdR9Vb9IjPRlkvN074zdKDVwIhAKJb\nRF3C+CMFb0wXme/ovcDeM1+3W/UmSHYUW4b3WYq4\n-----END
15882
RSA PRIVATE KEY-----"}]'
15983
headers:
@@ -164,67 +88,73 @@ interactions:
16488
Connection:
16589
- keep-alive
16690
Content-Length:
167-
- '602'
91+
- '606'
16892
Content-Type:
16993
- application/json
17094
GGShield-Command-Id:
171-
- 0705b453-f434-4c4c-8c80-3ecd4d7ad679
95+
- 2160e3a2-c12b-40f3-83de-f610ed3a643b
17296
GGShield-Command-Path:
17397
- external
17498
GGShield-OS-Name:
17599
- ubuntu
176100
GGShield-OS-Version:
177-
- '22.04'
101+
- '24.04'
178102
GGShield-Python-Version:
179-
- 3.11.8
103+
- 3.11.10
180104
GGShield-Version:
181-
- 1.33.0
105+
- 1.38.1
182106
User-Agent:
183-
- pygitguardian/1.18.0 (Linux;py3.11.8)
107+
- pygitguardian/1.20.0 (Linux;py3.11.10)
184108
mode:
185109
- path
110+
scan_options:
111+
- '{"show_secrets": false, "ignored_detectors_count": 0, "ignored_matches_count":
112+
0, "ignored_paths_count": 0, "ignore_known_secrets": false, "with_incident_details":
113+
false, "has_prereceive_remediation_message": false, "all_secrets": false}'
186114
method: POST
187115
uri: https://api.gitguardian.com/v1/multiscan?all_secrets=True
188116
response:
189117
body:
190118
string:
191119
'[{"policy_break_count":1,"policies":["Secrets detection"],"policy_breaks":[{"type":"RSA
192-
Private Key","policy":"Secrets detection","matches":[{"type":"apikey","match":"-----BEGIN
193-
RSA PRIVATE KEY-----\nMIIBOgIBAAJBAIIRkYjxjE3KIZiEc8k4sWWGNsPYRNE0u0bl5oFVApPLm+uXQ/4l\nbKO9LFtMiVPy700oMWLScwAN5OAiqVLMvHUCAwEAAQJANLr8nmEWuV6t2hAwhK5I\nNNmBkEo4M/xFxEtl9J7LKbE2gtNrlCQiJlPP1EMhwAjDOzQcJ3lgFB28dkqH5rMW\nTQIhANrCE7O+wlCKe0WJqQ3lYlHG91XWyGVgfExJwBDsAD9LAiEAmDY5OSsH0n2A\n22tthkAvcN1s66lG+0DztOVJ4QLI2z8CIBPeDGwGpx8pdIicN/5LFuLWbyAcoZaT\nbLaA/DCNPniBAiA0l//bzg+M3srIhm04xzLdR9Vb9IjPRlkvN074zdKDVwIhAKJb\nRF3C+CMFb0wXme/ovcDeM1+3W/UmSHYUW4b3WYq4\n-----END
194-
RSA PRIVATE KEY-----","index_start":0,"index_end":491,"line_start":1,"line_end":9}],"is_excluded":false,"exclude_reason":null,"incident_url":"","known_secret":false,"validity":"no_checker","diff_kind":null}],"is_diff":false}]'
120+
Private Key","detector_name":"private_key_rsa","detector_group_name":"private_key_rsa","documentation_url":"https://docs.gitguardian.com/secrets-detection/secrets-detection-engine/detectors/specifics/private_key_rsa","policy":"Secrets
121+
detection","matches":[{"type":"apikey","match":"-----BEGIN RSA PRIVATE KEY-----\nMIIBOgIBAAJBAIIRkYjxjE3KIZiEc8k4sWWGNsPYRNE0u0bl5oFVApPLm+uXQ/4l\nbKO9LFtMiVPy700oMWLScwAN5OAiqVLMvHUCAwEAAQJANLr8nmEWuV6t2hAwhK5I\nNNmBkEo4M/xFxEtl9J7LKbE2gtNrlCQiJlPP1EMhwAjDOzQcJ3lgFB28dkqH5rMW\nTQIhANrCE7O+wlCKe0WJqQ3lYlHG91XWyGVgfExJwBDsAD9LAiEAmDY5OSsH0n2A\n22tthkAvcN1s66lG+0DztOVJ4QLI2z8CIBPeDGwGpx8pdIicN/5LFuLWbyAcoZaT\nbLaA/DCNPniBAiA0l//bzg+M3srIhm04xzLdR9Vb9IjPRlkvN074zdKDVwIhAKJb\nRF3C+CMFb0wXme/ovcDeM1+3W/UmSHYUW4b3WYq4\n-----END
122+
RSA PRIVATE KEY-----","index_start":0,"index_end":491,"line_start":1,"line_end":9}],"is_excluded":false,"exclude_reason":null,"incident_url":"https://dashboard.gitguardian.com/workspace/518431/incidents/9787731","known_secret":true,"validity":"no_checker","diff_kind":null}],"is_diff":false}]'
195123
headers:
196124
access-control-expose-headers:
197125
- X-App-Version
198126
allow:
199127
- POST, OPTIONS
200128
content-length:
201-
- '872'
129+
- '1143'
202130
content-type:
203131
- application/json
204132
cross-origin-opener-policy:
205133
- same-origin
206134
date:
207-
- Wed, 27 Nov 2024 12:13:35 GMT
135+
- Tue, 22 Apr 2025 13:27:58 GMT
208136
referrer-policy:
209137
- strict-origin-when-cross-origin
210138
server:
211139
- istio-envoy
212140
strict-transport-security:
213141
- max-age=31536000; includeSubDomains
142+
transfer-encoding:
143+
- chunked
214144
vary:
215-
- Cookie
145+
- Accept-Encoding,Cookie
216146
x-app-version:
217-
- v2.121.0
147+
- v2.193.0
218148
x-content-type-options:
219149
- nosniff
220150
- nosniff
221151
x-envoy-upstream-service-time:
222-
- '65'
152+
- '84'
223153
x-frame-options:
224154
- DENY
225155
- SAMEORIGIN
226156
x-secrets-engine-version:
227-
- 2.127.0
157+
- 2.136.1
228158
x-xss-protection:
229159
- 1; mode=block
230160
status:

0 commit comments

Comments
 (0)