Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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-zA-Z0-9]{32}|[a-zA-Z0-9]{84}))\b`)
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated

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=uQ9XsjB7aM2eVt5rL1pZcW6yGk4nF8oHd3RzXaYbT7vUjKmQeP5fNwL9oS2tH1rJ3pZxDkMvYeWq0bAs`,
want: []string{"uQ9XsjB7aM2eVt5rL1pZcW6yGk4nF8oHd3RzXaYbT7vUjKmQeP5fNwL9oS2tH1rJ3pZxDkMvYeWq0bAs"},
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
},
{
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: Rk7mTz3nWx9pLq2vBs5yJd8cFg1hNa6oUi4eXwYrKbQjVm0tPl5sDf3gHn7kMz9aRcWx2bYu4eL"`,
want: []string{"Rk7mTz3nWx9pLq2vBs5yJd8cFg1hNa6oUi4eXwYrKbQjVm0tPl5sDf3gHn7kMz9aRcWx2bYu4eL"},
},
{
name: "84-character key - Python SDK",
input: `from openai import AzureOpenAI
client = AzureOpenAI(
azure_endpoint="https://team-ai.openai.azure.com/",
api_key="Ht5mNr9wXz3pLq7vBs2yJd6cFg8hKa1oUi4eTxYrQbMjVn0kPl5sDf3gRn7wMz9aXcWx2bYu4eLk0q",
)`,
want: []string{"Ht5mNr9wXz3pLq7vBs2yJd6cFg8hKa1oUi4eTxYrQbMjVn0kPl5sDf3gRn7wMz9aXcWx2bYu4eLk0q"},
},
{
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
Loading