Skip to content

Commit

Permalink
Added min token length check: fixes TykTechnologies#1681 (TykTechnolo…
Browse files Browse the repository at this point in the history
…gies#1692)

Added new internal `min_token_length` param
  • Loading branch information
lonelycode authored and buger committed May 11, 2018
1 parent 33f7149 commit b95bd65
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ type Config struct {
NewRelic NewRelicConfig `json:"newrelic"`
VersionHeader string `json:"version_header"`
EnableHashedKeysListing bool `json:"enable_hashed_keys_listing"`
MinTokenLength int `json:"min_token_length"`
}

type CertData struct {
Expand Down
5 changes: 4 additions & 1 deletion lint/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ const confSchema = `{
},
"enable_hashed_keys_listing": {
"type": "boolean"
}
},
"min_token_length": {
"type": "integer"
}
}
}`
10 changes: 10 additions & 0 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ func (t BaseMiddleware) ApplyPolicies(key string, session *user.SessionState) er
// CheckSessionAndIdentityForValidKey will check first the Session store for a valid key, if not found, it will try
// the Auth Handler, if not found it will fail
func (t BaseMiddleware) CheckSessionAndIdentityForValidKey(key string) (user.SessionState, bool) {
minLength := t.Spec.GlobalConfig.MinTokenLength
if minLength == 0 {
// See https://github.com/TykTechnologies/tyk/issues/1681
minLength = 3
}

if len(key) <= minLength {
return user.SessionState{IsInactive: true}, false
}

// Try and get the session from the session store
log.Debug("Querying local cache")
cacheKey := key
Expand Down

0 comments on commit b95bd65

Please sign in to comment.