Overly permissive regular expression range for artifact type validation#466
Merged
Overly permissive regular expression range for artifact type validation#466
Conversation
…ar expression range Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #466 +/- ##
============================================
+ Coverage 87.25% 88.10% +0.84%
Complexity 653 653
============================================
Files 39 39
Lines 2001 2001
Branches 226 226
============================================
+ Hits 1746 1763 +17
+ Misses 162 145 -17
Partials 93 93 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
@copilot This regex is not related to token. But for a media type or OCI artifact type. Can you ensure it's valid? |
Contributor
|
@jonesbusy I've opened a new pull request, #467, to work on those changes. Once the pull request is ready, I'll request review from you. |
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.
Potential fix for https://github.com/oras-project/oras-java/security/code-scanning/38
To fix this problem while maintaining correct (and standards-compliant) functionality, we should modify the regular expression to explicitly list all valid characters allowed in the media type "token" as defined by RFC6838/RFC2045. The RFC specifies the allowed characters for
tokenas:[A-Za-z0-9!#$%&'*+.^_{}|~-]That is, only a handful of ASCII symbols, alphanumerics, and the specified specials—not a broad range. The dash (-) should be either at the start or end of the character class to be literal, and special characters like^do *not* need to be included unless intended. Edit only line 60 (the regex) inArtifactType.java` accordingly. No new imports or helpers are needed.Suggested fixes powered by Copilot Autofix. Review carefully before merging.