Skip to content

Commit 1ae95e2

Browse files
committed
fix(crowdstrike-plugin): handle cloud region URL parsing to prevent wrong region selection
1 parent a2ca1a6 commit 1ae95e2

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

plugins/crowdstrike/main.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,18 @@ func (p *CrowdStrikeProcessor) createClient() (*client.CrowdStrikeAPISpecificati
129129
errors.New("client ID or client secret is empty"), map[string]any{"process": "plugin_com.utmstack.crowdstrike"})
130130
}
131131

132+
cloudType, err := extractCloudFromURL(p.Cloud)
133+
if err != nil {
134+
return nil, catcher.Error("invalid cloud region configuration", err, map[string]any{
135+
"process": "plugin_com.utmstack.crowdstrike",
136+
"cloud_value": p.Cloud,
137+
})
138+
}
139+
132140
client, err := falcon.NewClient(&falcon.ApiConfig{
133141
ClientId: p.ClientID,
134142
ClientSecret: p.ClientSecret,
135-
Cloud: falcon.Cloud(p.Cloud),
143+
Cloud: cloudType,
136144
Context: context.Background(),
137145
})
138146
if err != nil {
@@ -142,6 +150,29 @@ func (p *CrowdStrikeProcessor) createClient() (*client.CrowdStrikeAPISpecificati
142150
return client, nil
143151
}
144152

153+
func extractCloudFromURL(cloudValue string) (falcon.CloudType, error) {
154+
trimmed := strings.TrimSpace(cloudValue)
155+
156+
urlToRegion := map[string]string{
157+
"api.crowdstrike.com": "us-1",
158+
"api.us-2.crowdstrike.com": "us-2",
159+
"api.eu-1.crowdstrike.com": "eu-1",
160+
"api.laggar.gcw.crowdstrike.com": "us-gov-1",
161+
"api.us-gov-2.crowdstrike.mil": "us-gov-2",
162+
}
163+
164+
if strings.Contains(trimmed, "://") || strings.Contains(trimmed, ".crowdstrike.") {
165+
for host, region := range urlToRegion {
166+
if strings.Contains(trimmed, host) {
167+
return falcon.CloudValidate(region)
168+
}
169+
}
170+
return 0, fmt.Errorf("unrecognized CrowdStrike URL: %s", trimmed)
171+
}
172+
173+
return falcon.CloudValidate(trimmed)
174+
}
175+
145176
func (p *CrowdStrikeProcessor) getEvents() ([]string, error) {
146177
client, err := p.createClient()
147178
if err != nil {

0 commit comments

Comments
 (0)