-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[TT-11048] Regex on endpoint list issue #7146
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
Conversation
This PR is too huge for one to review 💔
Consider breaking it down into multiple small PRs. Check out this guide to learn more about PR best-practices. |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
API Changes --- prev.txt 2025-07-10 07:42:13.329705936 +0000
+++ current.txt 2025-07-10 07:42:03.922818810 +0000
@@ -3556,6 +3556,7 @@
type OAS struct {
openapi3.T
+ // Has unexported fields.
}
OAS holds the upstream OAS definition as well as adds functionality like
custom JSON marshalling.
@@ -3574,10 +3575,10 @@
func (s *OAS) Clone() (*OAS, error)
Clone creates a deep copy of the OAS object and returns a new instance.
-func (s *OAS) ExtractTo(api *apidef.APIDefinition)
+func (s *OAS) ExtractTo(api *apidef.APIDefinition) error
ExtractTo extracts *OAS into *apidef.APIDefinition.
-func (s *OAS) Fill(api apidef.APIDefinition)
+func (s *OAS) Fill(api apidef.APIDefinition) error
Fill fills *OAS definition from apidef.APIDefinition.
func (s *OAS) GetTykExtension() *XTykAPIGateway
@@ -3591,6 +3592,10 @@
func (s *OAS) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaller.
+func (s *OAS) Normalize() error
+ Normalize normalizes path to acceptable form by openapi. If API has named
+ RegExp it will be converted to accepted form of api by OAS.
+
func (s *OAS) RemoveTykExtension()
RemoveTykExtension clears the Tyk extensions from *OAS.
@@ -5508,9 +5513,14 @@
type Options[O any] []Option[O]
func New[O any](opts []Option[O]) Options[O]
+ New options instance.
func (o Options[O]) Build(baseVal O) *O
+func (o Options[O]) Prepend(opts ...Option[O]) Options[O]
+ Prepend adds options at the beginning of the list. Can be used for adding
+ default options.
+
# Package: ./config
package config // import "github.com/TykTechnologies/tyk/config"
@@ -10472,12 +10482,6 @@
func (k *OpenIDMW) ProcessRequest(w http.ResponseWriter, r *http.Request, _ interface{}) (error, int)
-type Operation struct {
- *oas.Operation
-
- // Has unexported fields.
-}
-
type OrganizationMonitor struct {
*BaseMiddleware
@@ -11719,7 +11723,7 @@
func (k *ValidateRequest) Name() string
-func (k *ValidateRequest) ProcessRequest(w http.ResponseWriter, r *http.Request, _ interface{}) (error, int)
+func (k *ValidateRequest) ProcessRequest(_ http.ResponseWriter, r *http.Request, _ interface{}) (error, int)
ProcessRequest will run any checks on the request on the way through the
system, return an error to have the chain fail
|
This reverts commit a8ff55c.
/probe review |
Code Review: Regex on Endpoint List Issue (PR #7146)SummaryThis PR addresses a critical bug in the path normalization functionality of Tyk Gateway, specifically in the handling of regex patterns in endpoint paths. The core issue is in the Critical IssuesBug in Digit DetectionThe func isDigit(s byte) bool {
return s >= '0' && s <= '0' // Bug: Only recognizes '0' as a digit
} This function is supposed to check if a byte is a digit (0-9), but it's incorrectly checking if the byte is exactly '0' (since the range is from '0' to '0'). This means that only the character '0' will be recognized as a digit, and all other digits ('1' through '9') will not be recognized. The PR correctly fixes this by changing the upper bound from '0' to '9': func isDigit(s byte) bool {
return s >= '0' && s <= '9' // Fixed: Recognizes all digits 0-9
} Impact of the BugThis bug has significant implications:
For example, a path like PR ImprovementsBeyond fixing the core bug, this PR introduces several improvements:
The path normalization is particularly important because it allows Tyk to support both its own extended path format (which includes regex patterns) and the standard OpenAPI path format. ConclusionThis PR addresses a critical bug that would affect any API definition using regex patterns with digits in endpoint paths. The fix is minimal and focused on the specific issue, while also introducing additional improvements to make the path normalization system more robust. The comprehensive test coverage ensures that the fix works correctly for various path formats and edge cases. Tip: Mention me again using |
Analysis of PR #7146: Regex on Endpoint List IssueSummaryThis PR addresses a critical bug in the path normalization functionality of Tyk Gateway, specifically in the handling of regex patterns in endpoint paths. The core issue is in the The BugThe root cause of the issue is in the func isDigit(s byte) bool {
return s >= '0' && s <= '0' // Bug: Only recognizes '0' as a digit
} This function is supposed to check if a byte is a digit (0-9), but it's incorrectly checking if the byte is exactly '0' (since the range is from '0' to '0'). This means that only the character '0' will be recognized as a digit, and all other digits ('1' through '9') will not be recognized. The fix is straightforward: func isDigit(s byte) bool {
return s >= '0' && s <= '9' // Fixed: Recognizes all digits 0-9
} Impact of the BugThis bug has significant implications:
For example, a path like Key Changes1. Robust Path NormalizationThe PR introduces a comprehensive path normalization system:
2. Refactored Operation Path Parsing
3. Enhanced Validation
4. Comprehensive Test Coverage
Code Quality Improvements
Potential IssuesThere are a couple of minor issues that should be addressed:
ConclusionThis PR fixes a critical bug that would affect any API definition using regex patterns with digits in endpoint paths. The fix is minimal and focused on the specific issue, while also introducing additional improvements to make the path normalization system more robust. The comprehensive test coverage ensures that the fix works correctly for various path formats and edge cases. The PR is well-structured and includes all necessary changes to fix the issue and improve the overall code quality. The two minor issues mentioned should be addressed before merging, but they don't affect the core functionality of the fix. Tip: Mention me again using |
Analysis of PR #7146: Regex on Endpoint List IssueThis PR addresses a critical bug in the path normalization functionality of Tyk Gateway, specifically in the handling of regex patterns in endpoint paths. The Core IssueThe bug is in the func isDigit(s byte) bool {
return s >= '0' && s <= '0' // Bug: Only recognizes '0' as a digit
} This function is supposed to check if a byte is a digit (0-9), but it's incorrectly checking if the byte is exactly '0' (since the range is from '0' to '0'). This means that only the character '0' would be recognized as a digit, and all other digits ('1' through '9') would not be recognized. The PR correctly fixes this by changing the upper bound from '0' to '9': func isDigit(s byte) bool {
return s >= '0' && s <= '9' // Fixed: Recognizes all digits 0-9
} Impact of the BugThis bug has significant implications:
For example, a path like PR ImprovementsBeyond fixing the core bug, this PR introduces several improvements:
The path normalization is particularly important because it allows Tyk to support both its own extended path format (which includes regex patterns) and the standard OpenAPI path format. Security ImplicationsThe bug could potentially have security implications as it might cause certain path-based security rules to be bypassed if they rely on regex patterns containing digits other than '0'. The fix ensures that all path patterns are correctly parsed and normalized, maintaining the intended security constraints. Tip: Mention me again using |
Analysis of PR #7146: Regex on Endpoint List IssueThis PR addresses a critical bug in the path normalization functionality of Tyk Gateway, specifically in the handling of regex patterns in endpoint paths. The BugThe core issue is in the func isDigit(s byte) bool {
return s >= '0' && s <= '0' // Bug: Only recognizes '0' as a digit
} This function is supposed to check if a byte is a digit (0-9), but it's incorrectly checking if the byte is exactly '0' (since the range is from '0' to '0'). This means that only the character '0' will be recognized as a digit, and all other digits ('1' through '9') will not be recognized. The PR fixes this by changing the upper bound from '0' to '9': func isDigit(s byte) bool {
return s >= '0' && s <= '9' // Fixed: Recognizes all digits 0-9
} Impact of the BugThis bug has significant implications:
PR ImprovementsBeyond fixing the core bug, this PR introduces several improvements:
The test suite also includes negative test cases to ensure proper error handling for malformed paths. Implementation DetailsThe PR introduces a new path normalization package (
The parser is particularly sophisticated, handling various path formats including:
ConclusionThis PR fixes a critical bug that would affect any API definition using regex patterns with digits in endpoint paths. The fix is minimal and focused on the specific issue, while also introducing additional improvements to make the path normalization system more robust. The comprehensive test coverage ensures that the fix works correctly for various path formats and edge cases. The path normalization functionality is crucial for Tyk Gateway as it allows proper handling of API endpoints with complex path patterns, ensuring correct routing and parameter extraction. Tip: Mention me again using |
Analysis of PR #7146: Regex on Endpoint List IssueThe BugThis PR addresses a critical bug in the path normalization functionality of Tyk Gateway, specifically in the handling of regex patterns in endpoint paths. The core issue is in the func isDigit(s byte) bool {
return s >= '0' && s <= '0' // Bug: Only recognizes '0' as a digit
} This function is supposed to check if a byte is a digit (0-9), but it's incorrectly checking if the byte is exactly '0' (since the range is from '0' to '0'). This means that only the character '0' will be recognized as a digit, and all other digits ('1' through '9') will not be recognized. The FixThe PR fixes this by correcting the func isDigit(s byte) bool {
return s >= '0' && s <= '9' // Fixed: Recognizes all digits 0-9
} This simple one-character change ensures that all digits from 0 to 9 are properly recognized during path parsing. Impact of the BugThis bug has significant implications for path normalization and regex pattern handling:
For example, a path like Additional ImprovementsBeyond fixing the core bug, this PR introduces several improvements to the path normalization system:
The PR also addresses two other issues identified during code review:
Test CoverageThe PR includes extensive test cases for path normalization, including paths with:
These tests ensure that the path normalization works correctly for all supported path formats and edge cases. ConclusionThis PR addresses a critical bug that would affect any API definition using regex patterns with digits in endpoint paths. The fix is straightforward - changing a single character in the The comprehensive test coverage added in this PR ensures that the path normalization works correctly for various path formats and edge cases, making the API Gateway more robust in handling different types of endpoint paths. Tip: Mention me again using |
|
User description
TT-11048
Description
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
PR Type
Enhancement, Tests
Description
Introduce robust path normalization for OAS endpoint paths
Refactor OAS operation path parsing and normalization logic
Add comprehensive tests for path normalization and parser
Enhance internal reflection clone test coverage
Changes walkthrough 📝
6 files
Add OAS path normalization and validation improvements
Refactor operation path parsing and mock response extraction
Add extended OAS validation options
Add Prepend method for options utility
Introduce robust parser for user-defined OAS paths
Implement normalized OAS path representation and normalization logic
4 files
Add comprehensive tests for path parser and normalization
Update OAS struct initialization for normalization flag
Update OAS test struct for normalization compatibility
Add deep pointer and map clone tests for reflect utility
1 files