fix: Update OpenAIDetector to support new token formats#964
Open
Mallikarjunadevops wants to merge 1 commit into
Open
fix: Update OpenAIDetector to support new token formats#964Mallikarjunadevops wants to merge 1 commit into
Mallikarjunadevops wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #951
What is this PR?
This PR updates
OpenAIDetectorto 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 likesk-proj-orsk-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 theOpenAIDetectorregex did not previously support.This PR introduces a new regex to the
denylistindetect_secrets/plugins/openai.pyto identify these new long-format tokens.Testing Evidence
Added test cases in
tests/plugins/openai_test.pycoveringsk-proj-andsk-svcacct-tokens, and verified they are successfully flagged.