[TT-16013] Gateway panics when validating JWT claims#7530
[TT-16013] Gateway panics when validating JWT claims#7530NurayAhmadova wants to merge 13 commits intomasterfrom
Conversation
🎯 Recommended Merge TargetsBased on JIRA ticket TT-16013: Gateway panics when validating JWT claims Fix Version: Tyk 5.11.0
Required:
📋 Workflow
|
🔍 Code Analysis Results{ The solution replaces the raw Files Changed AnalysisThe changes are primarily concentrated in the
Architecture & Impact Assessment
Scope Discovery & Context ExpansionThis PR introduces a breaking change to the internal Go API, although it maintains wire compatibility for JSON/YAML. The Proof of Breaking Change: The change is evident in the definition of the Before: // apidef/oas/authentication.go
// SecuritySchemes was a type alias for a map
type SecuritySchemes map[string]interface{}
type Authentication struct {
// ...
SecuritySchemes SecuritySchemes `bson:\"securitySchemes,omitempty\" json:\"securitySchemes,omitempty\"`
// ...
}After: // apidef/oas/authentication.go
// SecuritySchemes is now a struct
type SecuritySchemes struct {
container map[string]interface{}
mutex sync.RWMutex
}
type Authentication struct {
// ...
// The field is now a pointer to the struct
SecuritySchemes *SecuritySchemes `bson:\"securitySchemes,omitempty\" json:\"securitySchemes,omitempty\"`
// ...
}This change means that any Go code that consumes this package and directly initializes or assigns to the Powered by Visor from Probelabs Last updated: 2025-11-19T07:58:19.797Z | Triggered by: synchronize | Commit: f6eb0d8 💡 TIP: You can chat with Visor using |
🔍 Code Analysis Results✅ Security Check PassedNo security issues found – changes LGTM. ✅ Architecture Check PassedNo architecture issues found – changes LGTM. Performance Issues (1)
✅ Quality Check PassedNo quality issues found – changes LGTM. Dependency Issues (1)
✅ Connectivity Check PassedNo connectivity issues found – changes LGTM. Powered by Visor from Probelabs Last updated: 2025-11-19T07:58:21.149Z | Triggered by: synchronize | Commit: f6eb0d8 💡 TIP: You can chat with Visor using |
|
API Changes --- prev.txt 2025-11-27 08:23:05.749089251 +0000
+++ current.txt 2025-11-27 08:22:55.702058828 +0000
@@ -2341,6 +2341,8 @@
func (ap *AuthenticationPlugin) Fill(api apidef.APIDefinition)
type Basic struct {
+ SecuritySchemeMarkerImpl
+
// Enabled activates the basic authentication mode.
// Tyk classic API definition: `use_basic_auth`
Enabled bool `bson:"enabled" json:"enabled"` // required
@@ -2756,6 +2758,7 @@
CustomPlugin configures custom plugin.
type CustomPluginAuthentication struct {
+ SecuritySchemeMarkerImpl
// Enabled activates the CustomPluginAuthentication authentication mode.
//
// Tyk classic API definition: `enable_coprocess_auth`/`use_go_plugin_auth`.
@@ -2975,6 +2978,8 @@
and jsvm events are supported.
type ExternalOAuth struct {
+ SecuritySchemeMarkerImpl
+
// Enabled activates external oauth functionality.
//
// Tyk classic API definition: `external_oauth.enabled`.
@@ -3158,6 +3163,8 @@
Fill fills *GlobalRequestSizeLimit from apidef.APIDefinition.
type HMAC struct {
+ SecuritySchemeMarkerImpl
+
// Enabled activates the HMAC authentication mode.
//
// Tyk classic API definition: `enable_signature_checking`.
@@ -3446,6 +3453,8 @@
endpoint and its cache timeout.
type JWT struct {
+ SecuritySchemeMarkerImpl
+
// Enabled activates the basic authentication mode.
//
// Tyk classic API definition: `enable_jwt`
@@ -3856,6 +3865,8 @@
by calling OAS.validateSecurity() function.
type OAuth struct {
+ SecuritySchemeMarkerImpl
+
// Enabled activates the OAuth middleware.
//
// Tyk classic API definition: `use_oauth2`.
@@ -4437,18 +4448,54 @@
}
SecurityScheme defines an Importer interface for security schemes.
-type SecuritySchemes map[string]interface{}
- SecuritySchemes holds security scheme values, filled with Import().
+type SecuritySchemeMarker interface {
+ // Has unexported methods.
+}
+
+type SecuritySchemeMarkerImpl struct{}
+
+type SecuritySchemes struct {
+ // Has unexported fields.
+}
+ SecuritySchemes zero value is usable. Methods lazily initialize internal
+ state. Recommendation: prefer NewSecuritySchemes for clarity and explicit
+ initialization.
+
+func (ss SecuritySchemes) Get(key string) (SecuritySchemeMarker, bool)
+ Get retrieves a security scheme by name. It returns the stored value and
+ true when present, otherwise (nil, false).
func (ss SecuritySchemes) GetBaseIdentityProvider() (res apidef.AuthTypeEnum)
GetBaseIdentityProvider returns the identity provider by precedence from
SecuritySchemes.
-func (ss SecuritySchemes) Import(name string, nativeSS *openapi3.SecurityScheme, enable bool) error
- Import takes the openapi3.SecurityScheme as argument and applies it to
- the receiver. The SecuritySchemes receiver is a map, so modification of
- the receiver is enabled, regardless of the fact that the receiver isn't a
- pointer type. The map is a pointer type itself.
+func (ss SecuritySchemes) GetVal(key string) interface{}
+ GetVal retrieves a security scheme by name. It returns the stored value and
+ true when present, otherwise nil.
+
+func (ss SecuritySchemes) Iter() iter.Seq2[string, interface{}]
+ Iter returns a snapshot under a short read lock to avoid holding locks
+ during iteration. This allocates per call. Given the typical small number of
+ schemes, the trade-off is acceptable.
+
+func (ss SecuritySchemes) Len() int
+ Len reports the number of registered security schemes. A nil receiver
+ reports zero.
+
+func (ss *SecuritySchemes) MarshalJSON() ([]byte, error)
+ MarshalJSON implements json.Marshaler.
+
+func (ss *SecuritySchemes) MarshalYAML() (interface{}, error)
+ MarshalYAML makes SecuritySchemes YAML-friendly by exposing its container
+ map.
+
+func (ss SecuritySchemes) Set(key string, value SecuritySchemeMarker) SecuritySchemes
+
+func (ss *SecuritySchemes) UnmarshalJSON(b []byte) error
+ UnmarshalJSON implements json.Unmarshaler.
+
+func (ss *SecuritySchemes) UnmarshalYAML(n *yaml.Node) error
+ UnmarshalYAML populates SecuritySchemes.container from YAML.
type Server struct {
// ListenPath is the base path on Tyk to which requests for this API should
@@ -4776,6 +4823,8 @@
Fill fills *TLSTransport from apidef.ServiceDiscoveryConfiguration.
type Token struct {
+ SecuritySchemeMarkerImpl
+
// Enabled activates the token based authentication mode.
//
// Tyk classic API definition: `auth_configs["authToken"].use_standard_auth` |
36613ec to
d33c6b9
Compare
|
/review making SecurityScheme to a pointer is this a breaking change and why? bring proof of why you think it's abreaking change |
69218c0 to
92f9741
Compare
shults
left a comment
There was a problem hiding this comment.
Would you mind fixing race condition in MarshalYAML method?
| return map[string]interface{}{}, nil | ||
| } | ||
| // Return the raw map so yaml can encode it normally. | ||
| return ss.container, nil |
There was a problem hiding this comment.
This code does not like to be safe.
Map resize can occur during yaml marshaling.
It would be better to return copy of the map.
There was a problem hiding this comment.
return reflect.Clone(ss.sontainer), nil
or
return yaml.Marshal(ss.container), nil -> this seams better because of additon allocation is no needed
| v, ok := ss.Get("x") | ||
|
|
||
| if !ok { | ||
| t.Fatal("expected ok") |
There was a problem hiding this comment.
I would rather use testify assert/require, but it's up to you.
926b95b to
b0a65f3
Compare
b1a2452 to
f6eb0d8
Compare
f6eb0d8 to
012db84
Compare
|
{ Files Changed Analysis\\
Architecture & Impact Assessment\\
|
Security Issues (2)
Architecture Issues (5)
Performance Issues (2)
Quality Issues (4)
Powered by Visor from Probelabs Last updated: 2025-11-27T08:27:04.471Z | Triggered by: pr_updated | Commit: 65bd416 💡 TIP: You can chat with Visor using |
|
bcb9f9b to
c042d35
Compare
ad39664 to
296dd3f
Compare
|
This PR has been closed in favour of #7579. |



Description
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
fork, don't request your
master!masterbranch (left side). Also, you should startyour branch off our latest
master.go mod tidy && go mod vendorgo fmt -sgo vetTicket Details
TT-16013
Generated at: 2025-11-27 08:22:39