Skip to content

fix: Update OpenAIDetector to support new token formats#964

Open
Mallikarjunadevops wants to merge 1 commit into
Yelp:masterfrom
Mallikarjunadevops:fix-openai-tokens
Open

fix: Update OpenAIDetector to support new token formats#964
Mallikarjunadevops wants to merge 1 commit into
Yelp:masterfrom
Mallikarjunadevops:fix-openai-tokens

Conversation

@Mallikarjunadevops
Copy link
Copy Markdown

Fixes #951

What is this PR?

This PR updates OpenAIDetector to support OpenAI's newer API token formats.

Why?

OpenAI has deprecated the legacy fixed-prefix API tokens that contained the base64 string T3BlbkFJ (OpenAI). The new token formats (e.g., project-based tokens and service account tokens) start with prefixes like sk-proj- or sk-svcacct- followed by a long alphanumeric string without the legacy base64 component.

The issue #951 reported that Jupyter Notebook entries containing OpenAI API keys were not being detected. While the issue title attributes this to Jupyter Notebook files, the root cause is actually the new token format sk-proj-... that the OpenAIDetector regex did not previously support.

This PR introduces a new regex to the denylist in detect_secrets/plugins/openai.py to identify these new long-format tokens.

Testing Evidence

Added test cases in tests/plugins/openai_test.py covering sk-proj- and sk-svcacct- tokens, and verified they are successfully flagged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Jupyter notebook entries not properly detected

1 participant