Skip to content

Commit 0cf74fd

Browse files
Modify MSteams secrets: add tests, add pattern readability (#280)
1 parent 46a8be9 commit 0cf74fd

File tree

1 file changed

+21
-14
lines changed
  • sonar-text-plugin/src/main/resources/org/sonar/plugins/secrets/configuration

1 file changed

+21
-14
lines changed

sonar-text-plugin/src/main/resources/org/sonar/plugins/secrets/configuration/ms-teams.yaml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,33 @@ provider:
1515
patternNot:
1616
- "(\\w)\\1{5,}"
1717
- "(?i)test|abcd|1234"
18-
- "(?i)\
19-
YOURTENANTNAME|\
20-
mycompany|\
21-
yourorg|\
22-
team[_-]?name|\
23-
example|\
24-
contoso|\
25-
acmecorp"
18+
- "(?i)YOURTENANTNAME|mycompany|yourorg|(s|ex)ample"
19+
- "(?i)team[_-]?name"
20+
- "contoso|acmecorp"
2621

2722
rules:
2823
- rspecKey: S6721
2924
id: ms-teams-webhook-urls
3025
metadata:
3126
name: Microsoft Teams Webhook Urls
27+
detection:
28+
matching:
29+
# Structure:
30+
# https://tenant-name.webhook.office.com/webhookb2/guid@guid/IncomingWebhook/connectorId/guid
31+
# An MS GUID is in the following format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX where X is a hex digit
32+
pattern: "((?:https://)?\
33+
[a-z0-9_-]{1,50}\\.webhook\\.office\\.com/webhookb2/\
34+
[a-z0-9\\-]{1,50}@[a-z0-9\\-]{1,50}/IncomingWebhook/[a-z0-9]{1,50}/[a-z0-9\\-]{1,50})"
3235
examples:
36+
- text: |
37+
# Noncompliant code example
38+
props.set("teams_webhook_url", "https://sonarcompany.webhook.office.com/webhookb2/52feb105-fe74-52b9-8e90-5d165916fe22@61c6aa5a3-6531-4e28-9c0b-33ba1a8aa1ff/IncomingWebhook/f7fb2308e5f14431ace5b7cd0e670e42/4563618c-b03b-4e80-b093-28bb4ff11de8")
39+
containsSecret: true
40+
match: https://sonarcompany.webhook.office.com/webhookb2/52feb105-fe74-52b9-8e90-5d165916fe22@61c6aa5a3-6531-4e28-9c0b-33ba1a8aa1ff/IncomingWebhook/f7fb2308e5f14431ace5b7cd0e670e42/4563618c-b03b-4e80-b093-28bb4ff11de8
41+
- text: |
42+
# Compliant solution
43+
props.set("teams_webhook_url", System.getenv("TEAMS_WEBHOOK_URL"))
44+
containsSecret: false
3345
- text: |
3446
var webhookUrl = "https://companyname.webhook.office.com/webhookb2/5bf015e2-ce92-42a8-8e90-92552d6ef161@0c6aa5a3-6531-4e28-9c0b-33ba1a8aa1ff/IncomingWebhook/f7fb2308e5f14431ace5b7cd0e670e42/4563618c-b03b-4e80-b093-28bb4ff11de8";
3547
var client = new HttpClient();
@@ -53,9 +65,4 @@ provider:
5365
'1': 'https://mycompany.webhook.office.com/webhookb2/f49c28c6-d10b-412c-b961-fge456bd@c1a7fa9b-90b3-49ab-b5e2-345HG88c/IncomingWebhook/b43c20SDSGFG56712d848bc1cebb17/53ee2e22-a867-4e74-868a-F3fs3935',
5466
}
5567
containsSecret: false
56-
detection:
57-
matching:
58-
# Structure:
59-
# https://tenant-name.webhook.office.com/webhookb2/guid@guid/IncomingWebhook/connectorId/guid
60-
# An MS GUID is in the following format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX where X is a hex digit
61-
pattern: "((https://)?[a-z0-9_-]{1,50}\\.webhook\\.office\\.com/webhookb2/[a-z0-9\\-]{1,50}@[a-z0-9\\-]{1,50}/IncomingWebhook/[a-z0-9]{1,50}/[a-z0-9\\-]{1,50})"
68+

0 commit comments

Comments
 (0)