TykTechnologies / tyk

Tyk Open Source API Gateway written in Go, supporting REST, GraphQL, TCP and gRPC protocols
Other
9.76k stars 1.09k forks source link

Merging to release-5.6: [TT-13128] Updated description for prefix and suffix matching config options (#6555) #6558

Closed buger closed 2 months ago

buger commented 2 months ago

User description

TT-13128 Updated description for prefix and suffix matching config options (#6555)

PR Type

documentation


Description


Changes walkthrough ๐Ÿ“

Relevant files
Documentation
config.go
Clarify and enhance documentation for path matching options

config/config.go
  • Updated descriptions for EnablePathPrefixMatching and
    EnablePathSuffixMatching.
  • Clarified the behavior of prefix and suffix matching.
  • Provided examples for both matching options.
  • Explained the impact on existing route definitions.
  • +35/-39 

    ๐Ÿ’ก PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions


    PR Type

    Documentation


    Description


    Changes walkthrough ๐Ÿ“

    Relevant files
    Documentation
    config.go
    Clarify and enhance documentation for path matching options

    config/config.go
  • Clarified the behavior of EnablePathPrefixMatching and
    EnablePathSuffixMatching.
  • Updated descriptions to explain the switch from wildcard to
    prefix/suffix matching.
  • Added examples to illustrate the differences between matching modes.
  • Noted the potential need for adjustments in existing route
    definitions.
  • +35/-39 

    ๐Ÿ’ก PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    github-actions[bot] commented 2 months ago

    PR Reviewer Guide ๐Ÿ”

    โฑ๏ธ Estimated effort to review: 2 ๐Ÿ”ต๐Ÿ”ตโšชโšชโšช
    ๐Ÿงช No relevant tests
    ๐Ÿ”’ No security concerns identified
    โšก No key issues to review
    github-actions[bot] commented 2 months ago

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add a safety check for simultaneous enabling of prefix and suffix matching ___ **Consider adding a check to ensure that EnablePathPrefixMatching and
    EnablePathSuffixMatching are not both enabled simultaneously without explicit
    intent, as this combination forces exact URL matching which might not be desirable
    in all cases. This can prevent configuration errors leading to unexpected behavior.** [config/config.go [429-448]](https://github.com/TykTechnologies/tyk/pull/6558/files#diff-fe44f09c4d5977b5f5eaea29170b6a0748819c9d02271746a20d81a5f3efca17R429-R448) ```diff +if EnablePathPrefixMatching && EnablePathSuffixMatching { + // Log warning or handle the case where both are enabled +} EnablePathPrefixMatching bool `json:"enable_path_prefix_matching"` EnablePathSuffixMatching bool `json:"enable_path_suffix_matching"` ```
    Suggestion importance[1-10]: 8 Why: The suggestion addresses a potential configuration error where both prefix and suffix matching are enabled simultaneously, leading to exact URL matching. Adding a check can prevent unintended behavior, making it a valuable improvement for robustness and error prevention.
    8
    github-actions[bot] commented 2 months ago

    API Changes

    --- prev.txt    2024-09-20 11:15:31.761918872 +0000
    +++ current.txt 2024-09-20 11:15:28.302915953 +0000
    @@ -5905,47 +5905,10 @@
        // Regular expressions and parameterized routes will be left alone regardless of this setting.
        EnableStrictRoutes bool `json:"enable_strict_routes"`
    
    -   // EnablePathPrefixMatching changes the URL matching from wildcard mode to prefix mode.
    -   // For example, `/json` matches `*/json*` by current default behaviour.
    -   // If prefix matching is enabled, the match will be performed as a prefix match (`/json*`).
    -   //
    -   // The `/json` url would be matched as `^/json` against the following paths:
    -   //
    -   // - Full listen path and versioning URL (`/listen-path/v4/json`)
    -   // - Stripped listen path URL (`/v4/json`)
    -   // - Stripped version information (`/json`) - match.
    -   //
    -   // If versioning is disabled then the following URLs are considered:
    -   //
    -   // - Full listen path and endpoint (`/listen-path/json`)
    -   // - Stripped listen path (`/json`) - match.
    -   //
    -   // For inputs that start with `/`, a prefix match is ensured by
    -   // prepending the start of string `^` caret.
    -   //
    -   // For all other cases, the pattern remains unmodified.
    -   //
    -   // Combine this option with `enable_path_suffix_matching` to achieve
    -   // exact url matching with `/json` being evaluated as `^/json$`.
    +   // Combining EnablePathPrefixMatching with EnablePathSuffixMatching will result in exact URL matching, with `/json` being evaluated as `^/json$`.
        EnablePathPrefixMatching bool `json:"enable_path_prefix_matching"`
    
    -   // EnablePathSuffixMatching changes the URL matching to match as a suffix.
    -   // For example: `/json` is matched as `/json$` against the following paths:
    -   //
    -   // - Full listen path and versioning URL (`/listen-path/v4/json`)
    -   // - Stripped listen path URL (`/v4/json`)
    -   // - Stripped version information (`/json`) - match.
    -   //
    -   // If versioning is disabled then the following URLs are considered:
    -   //
    -   // - Full listen path and endpoint (`/listen-path/json`)
    -   // - Stripped listen path (`/json`) - match.
    -   //
    -   // If the input pattern already ends with a `$` (`/json$`)
    -   // then the pattern remains unmodified.
    -   //
    -   // Combine this option with `enable_path_prefix_matching` to achieve
    -   // exact url matching with `/json` being evaluated as `^/json$`.
    +   // Combining EnablePathSuffixMatching with EnablePathPrefixMatching will result in exact URL matching, with `/json` being evaluated as `^/json$`.
        EnablePathSuffixMatching bool `json:"enable_path_suffix_matching"`
    
        // Disable TLS verification. Required if you are using self-signed certificates.
    sonarcloud[bot] commented 2 months ago

    Quality Gate Passed Quality Gate passed

    Issues
    0 New issues
    0 Accepted issues

    Measures
    0 Security Hotspots
    0.0% Coverage on New Code
    0.0% Duplication on New Code

    See analysis details on SonarCloud