Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/detectors/azure_openai/azure_openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
// TODO: Investigate custom `azure-api.net` endpoints.
// https://github.com/openai/openai-python#microsoft-azure-openai
azureUrlPat = regexp.MustCompile(`(?i)([a-z0-9-]+\.openai\.azure\.com)`)
azureKeyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"api[_.-]?key", "openai[_.-]?key"}) + `\b(?-i:([a-f0-9]{32}))\b`)
azureKeyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"api[_.-]?key", "openai[_.-]?key"}) + `\b(?-i:([a-f0-9]{32}|[a-zA-Z0-9]{84}))\b`)

invalidServices = simple.NewCache[struct{}]()
)
Expand Down Expand Up @@ -76,7 +76,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
for token := range tokens {
s1 := detectors.Result{
DetectorType: s.Type(),
Redacted: token[:3] + "..." + token[25:],
Redacted: token[:3] + "..." + token[len(token)-4:],
Raw: []byte(token),
SecretParts: map[string]string{"key": token},
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/detectors/azure_openai/azure_openai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,34 @@ func TestAzureOpenAI_Pattern(t *testing.T) {
}`,
want: []string{"57d2de35873840b5ad59d742e90e974e"},
},
{
name: "84-character key - environment variable",
input: `export OPENAI_API_BASE=https://myservice-east.openai.azure.com/
export OPENAI_API_KEY=aB1cD2eF3gH4iJ5kL6mN7oP8qR9sT0aB1cD2eF3gH4iJ5kL6mN7oP8qR9sT0aB1cD2eF3gH4iJ5kL6mN7oP8`,
want: []string{"aB1cD2eF3gH4iJ5kL6mN7oP8qR9sT0aB1cD2eF3gH4iJ5kL6mN7oP8qR9sT0aB1cD2eF3gH4iJ5kL6mN7oP8"},
},
{
name: "84-character key - curl command",
input: `curl -X POST "https://prod-openai.openai.azure.com/openai/deployments/gpt-4o-mini/chat/completions?api-version=2025-01-01-preview" \
-H "Content-Type: application/json" \
-H "api-key: Zz9Yy8Xx7Ww6Vv5Uu4Tt3Ss2Rr1Qq0Zz9Yy8Xx7Ww6Vv5Uu4Tt3Ss2Rr1Qq0Zz9Yy8Xx7Ww6Vv5Uu4Tt3Ss2"`,
want: []string{"Zz9Yy8Xx7Ww6Vv5Uu4Tt3Ss2Rr1Qq0Zz9Yy8Xx7Ww6Vv5Uu4Tt3Ss2Rr1Qq0Zz9Yy8Xx7Ww6Vv5Uu4Tt3Ss2"},
},
{
name: "84-character key - Python SDK",
input: `from openai import AzureOpenAI
client = AzureOpenAI(
azure_endpoint="https://team-ai.openai.azure.com/",
api_key="a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5a1b2c3d4e5f6g7h8i9j0k1l2",
)`,
want: []string{"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5a1b2c3d4e5f6g7h8i9j0k1l2"},
},
{
name: "invalid - 50 character key (wrong length)",
input: `OPENAI_API_KEY=uQ9XsjB7aM2eVt5rL1pZcW6yGk4nF8oHd3RzXaYbT7vUjKm
https://test.openai.azure.com/`,
want: []string{},
},
}

for _, test := range tests {
Expand Down