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

[TT-1944/TT-12550/TT-12865] [5.0.14 backport] Backport critical fixes #6516

Closed jeffy-mathew closed 2 months ago

jeffy-mathew commented 2 months ago

… (#6515)

https://tyktech.atlassian.net/browse/TT-12865 and related 5.0.14 backports


Description

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

Checklist

github-actions[bot] commented 2 months ago

API Changes

--- prev.txt    2024-09-13 15:45:30.956303651 +0000
+++ current.txt 2024-09-13 15:45:27.416316375 +0000
@@ -4758,6 +4758,49 @@
    // 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$`.
+   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$`.
+   EnablePathSuffixMatching bool `json:"enable_path_suffix_matching"`
+
    // Disable TLS verification. Required if you are using self-signed certificates.
    SSLInsecureSkipVerify bool `json:"ssl_insecure_skip_verify"`

@@ -6445,10 +6488,16 @@
 func CloneAPI(a *APISpec) *APISpec

 func (a *APISpec) CheckSpecMatchesStatus(r *http.Request, rxPaths []URLSpec, mode URLStatus) (bool, interface{})
-    CheckSpecMatchesStatus checks if a url spec has a specific status
+    CheckSpecMatchesStatus checks if a URL spec has a specific status.
+    Deprecated: The function doesn't follow go return conventions (T, ok);
+    use FindSpecMatchesStatus;

 func (a *APISpec) Expired() bool

+func (a *APISpec) FindSpecMatchesStatus(r *http.Request, rxPaths []URLSpec, mode URLStatus) (*URLSpec, bool)
+    FindSpecMatchesStatus checks if a URL spec has a specific status and returns
+    the URLSpec for it.
+
 func (s *APISpec) FireEvent(name apidef.TykEvent, meta interface{})

 func (a *APISpec) GetSessionLifetimeRespectsKeyExpiration() bool
@@ -6470,7 +6519,13 @@

 func (a *APISpec) StopSessionManagerPool()

-func (a *APISpec) StripListenPath(r *http.Request, path string) string
+func (a *APISpec) StripListenPath(reqPath string) string
+    StripListenPath will strip the listen path from the URL, keeping version in
+    tact.
+
+func (a *APISpec) StripVersionPath(reqPath string) string
+    StripVersionPath will strip the version from the URL. The input URL should
+    already have listen path stripped.

 func (a *APISpec) URLAllowedAndIgnored(r *http.Request, rxPaths []URLSpec, whiteListStatus bool) (RequestStatus, interface{})
     URLAllowedAndIgnored checks if a url is allowed and ignored.
@@ -9081,7 +9136,6 @@
     system, return an error to have the chain fail

 type URLSpec struct {
-   Spec                      *regexp.Regexp
    Status                    URLStatus
    MethodActions             map[string]apidef.EndpointMethodMeta
    Whitelist                 apidef.EndPointMeta
@@ -9109,6 +9163,7 @@
    PersistGraphQL            apidef.PersistGraphQLMeta

    IgnoreCase bool
+   // Has unexported fields.
 }
     URLSpec represents a flattened specification for URLs, used to check if
     a proxy URL path is on any of the white, black or ignored lists. This is
@@ -10420,6 +10475,9 @@
 func Cert(domain string) tls.Certificate
     Generate cert

+func Exclusive(t *testing.T)
+    Exclusive uses a lock to gate only a single test running.
+
 func Flaky(t *testing.T, fake ...func() (bool, func(...interface{})))
     Flaky skips a flaky test in a CI environment

@@ -10518,6 +10576,7 @@
 func (r TCPTestRunner) Run(t testing.TB, testCases ...TCPTestCase) error

 type TestCase struct {
+   Host    string `json:",omitempty"`
    Method  string `json:",omitempty"`
    Path    string `json:",omitempty"`
    BaseURL string `json:",omitempty"`
@@ -10593,6 +10652,8 @@
 func MyPluginReturningError(rw http.ResponseWriter, r *http.Request)
 # Package: ./tests/regression

+package regression // import "github.com/TykTechnologies/tyk/tests/regression"
+
 # Package: ./trace

 package trace // import "github.com/TykTechnologies/tyk/trace"
sonarcloud[bot] commented 2 months ago

Quality Gate Failed Quality Gate failed

Failed conditions
55.9% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

lghiur commented 2 months ago

We created the release-5.0.14 branch from release-5-lts