Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make OpenAI regex more specific #1345

Merged
merged 2 commits into from
May 22, 2023

Conversation

nyanshak
Copy link
Contributor

  • OpenAI keys are in the format 'sk-' + 20 alphanumeric chars + the magic string 'OpenAI' base64-encoded + 20 alphanumeric chars.

Copy link
Collaborator

@ahrav ahrav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for the improvement here Brendan 😃

pkg/detectors/openai/openai.go Outdated Show resolved Hide resolved
@dustin-decker
Copy link
Contributor

The keyword on L45 could be changed to T3BlbkFJ, which will be a bit more specific and prevent the regex code path from running as often.

* OpenAI keys are in the format 'sk-' + 20 alphanumeric chars + the
  magic string 'OpenAI' base64-encoded + 20 alphanumeric chars.
* Use the more-specific magic word as a keyword to prevent check running
  as often.
* Fix typo in characters in regex by using named character classes.
@ahrav ahrav merged commit 3ab864a into trufflesecurity:main May 22, 2023
@nyanshak nyanshak deleted the improve-openai-key-regex branch May 22, 2023 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants