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

Allow underscores and hypens in the OpenAI key check #3494

Closed
wants to merge 10 commits into from

Conversation

thienlnam
Copy link

@thienlnam thienlnam commented Sep 8, 2024

Why are these changes needed?

Looks like underscores are now part of the OpenAI API keys, which are not matched in the existing regex.

This was a project API key I just generated that has this underscore (deleted so no longer active)
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

Here's what I was able to find about the API keys prefixes
Legacy User API keys:
sk-[rest]

Project API keys:
sk-proj-[rest]

New User Keys
sk-None-[rest]

Service Account Keys
sk-svcaat-[rest]

This change ensures that:

  1. Underscores are allowed in all parts of the key after the key prefix.
  2. All current API key formats (Legacy, Project, New User, Service Account) are still supported.

Related issue number

Closes #3345

Checks

Copy link

gitguardian bot commented Sep 8, 2024

⚠️ GitGuardian has uncovered 35 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
12853598 Triggered Generic High Entropy Secret e0bbcad test/oai/test_utils.py View secret
12853598 Triggered Generic High Entropy Secret be5b239 test/oai/test_utils.py View secret
10404693 Triggered Generic High Entropy Secret 5d71c8b test/oai/test_utils.py View secret
10404693 Triggered Generic High Entropy Secret be5b239 test/oai/test_utils.py View secret
12853599 Triggered Generic High Entropy Secret be5b239 test/oai/test_utils.py View secret
12853599 Triggered Generic High Entropy Secret 5d71c8b test/oai/test_utils.py View secret
10404694 Triggered Generic High Entropy Secret 5d71c8b test/oai/test_utils.py View secret
- - Generic High Entropy Secret be5b239 test/oai/test_utils.py View secret
- - Generic High Entropy Secret 5d71c8b test/oai/test_utils.py View secret
- - Generic High Entropy Secret be5b239 test/oai/test_utils.py View secret
- - Generic High Entropy Secret 5d71c8b test/oai/test_utils.py View secret
- - Generic High Entropy Secret a03112d test/oai/test_utils.py View secret
- - Generic High Entropy Secret e0bbcad test/oai/test_utils.py View secret
- - Generic High Entropy Secret 6b7053a test/oai/test_utils.py View secret
- - Generic High Entropy Secret d94b9ff test/oai/test_utils.py View secret
- - Generic High Entropy Secret e0bbcad test/oai/test_utils.py View secret
12853600 Triggered Generic High Entropy Secret d94b9ff test/oai/test_utils.py View secret
12853600 Triggered Generic High Entropy Secret a03112d test/oai/test_utils.py View secret
12853600 Triggered Generic High Entropy Secret e0bbcad test/oai/test_utils.py View secret
12853600 Triggered Generic High Entropy Secret 6b7053a test/oai/test_utils.py View secret
12853600 Triggered Generic High Entropy Secret e0bbcad test/oai/test_utils.py View secret
- - Generic High Entropy Secret be5b239 test/oai/test_utils.py View secret
- - Generic High Entropy Secret 5d71c8b test/oai/test_utils.py View secret
12853601 Triggered Generic High Entropy Secret d94b9ff test/oai/test_utils.py View secret
12853601 Triggered Generic High Entropy Secret a03112d test/oai/test_utils.py View secret
12853601 Triggered Generic High Entropy Secret 6b7053a test/oai/test_utils.py View secret
12853601 Triggered Generic High Entropy Secret be5b239 test/oai/test_utils.py View secret
12853601 Triggered Generic High Entropy Secret e0bbcad test/oai/test_utils.py View secret
10404696 Triggered Generic High Entropy Secret 5d71c8b test/oai/test_utils.py View secret
10422482 Triggered Generic High Entropy Secret 5d71c8b test/oai/test_utils.py View secret
10422482 Triggered Generic High Entropy Secret be5b239 test/oai/test_utils.py View secret
12853602 Triggered Generic High Entropy Secret d94b9ff test/oai/test_utils.py View secret
12853602 Triggered Generic High Entropy Secret 6b7053a test/oai/test_utils.py View secret
12853602 Triggered Generic High Entropy Secret e0bbcad test/oai/test_utils.py View secret
12853602 Triggered Generic High Entropy Secret a03112d test/oai/test_utils.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@thienlnam thienlnam changed the title Jack fix error valid open ai key Allow underscores in the OpenAI key check Sep 8, 2024
@thienlnam
Copy link
Author

@microsoft-github-policy-service agree

@thienlnam
Copy link
Author

Looks like the GitGuardian is catching the secrets added in the tests, but those are just key examples and not actual keys

@gagb
Copy link
Collaborator

gagb commented Sep 8, 2024

@jackgerrits @afourney what's the fix for the security checks?

@afourney
Copy link
Member

afourney commented Sep 8, 2024

@jackgerrits @afourney what's the fix for the security checks?

I am not sure. I tried reporting that it was a false alarm and it still triggers. I suppose the alternative is to remove any placeholder values.

@thienlnam
Copy link
Author

I tried adding #ggignore to the "api keys", but GitGuardian still triggered on those lines.

Let me know how you'd like to proceed - another option might be to just ignore the test file path in the .gitguardian.yaml config or adding an ignore-matches for these specific keys

@thienlnam
Copy link
Author

Also, funnily enough when I went to generate a new API key - I had another instance that which would not pass the regex which is hypens after the prefix so added support for that too

Ex. (Deleted key)
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

@thienlnam thienlnam changed the title Allow underscores in the OpenAI key check Allow underscores and hypens in the OpenAI key check Sep 10, 2024
@jackgerrits
Copy link
Member

I think we should consider just removing api key validation - if it is wrong then the API call will fail.

Would you be interested in working on that @thienlnam ?

@jackgerrits
Copy link
Member

Superseded by #3569

@jackgerrits jackgerrits mentioned this pull request Sep 25, 2024
3 tasks
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]: OpenAI API key format
4 participants