Skip to content

Commit

Permalink
Apply policies on key retrieval from API
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Aug 16, 2018
1 parent 9188ac6 commit 1d393cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ func handleGetDetail(sessionKey, apiID string, byHash bool) (interface{}, int) {
}

sessionManager := FallbackKeySesionManager
if spec := getApiSpec(apiID); spec != nil {
spec := getApiSpec(apiID)
if spec != nil {
sessionManager = spec.SessionManager
}

Expand All @@ -335,8 +336,18 @@ func handleGetDetail(sessionKey, apiID string, byHash bool) (interface{}, int) {
} else {
session.QuotaRemaining = remaining
}
} else {
log.WithFields(logrus.Fields{
"prefix": "api",
"key": obfuscateKey(sessionKey),
"error": err,
"status": "ok",
}).Info("Can't retrieve key quota")
}

mw := BaseMiddleware{Spec: spec}
mw.ApplyPolicies(sessionKey, &session)

log.WithFields(logrus.Fields{
"prefix": "api",
"key": obfuscateKey(sessionKey),
Expand Down
2 changes: 1 addition & 1 deletion middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (t BaseMiddleware) ApplyPolicies(key string, session *user.SessionState) er
}
// Check ownership, policy org owner must be the same as API,
// otherwise youcould overwrite a session key with a policy from a different org!
if policy.OrgID != t.Spec.OrgID {
if t.Spec != nil && policy.OrgID != t.Spec.OrgID {
err := fmt.Errorf("attempting to apply policy from different organisation to key, skipping")
log.Error(err)
return err
Expand Down

0 comments on commit 1d393cf

Please sign in to comment.