Skip to content

Commit

Permalink
We can check for the session details before updating access rights
Browse files Browse the repository at this point in the history
  • Loading branch information
Tit Petric committed Aug 16, 2023
1 parent 7a1605a commit 70de154
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions gateway/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,8 @@ func (gw *Gateway) applyPoliciesAndSave(keyName string, session *user.SessionSta

// calculate lifetime considering access rights
lifetime := gw.ApplyLifetime(session, spec)
if err := gw.GlobalSessionManager.UpdateSession(keyName, session, lifetime, isHashed); err != nil {
return err
}

return nil
return gw.GlobalSessionManager.UpdateSession(keyName, session, lifetime, isHashed)
}

// GetApiSpecsFromAccessRights from the session.AccessRights returns the collection of api specs
Expand Down Expand Up @@ -324,22 +321,28 @@ func (gw *Gateway) doAddOrUpdate(keyName string, newSession *user.SessionState,
}

if len(newSession.AccessRights) > 0 {
_, found := gw.GlobalSessionManager.SessionDetail(newSession.OrgID, keyName, isHashed)
if !found {
log.WithFields(logrus.Fields{
"prefix": "api",
"key": keyName,
"org_id": newSession.OrgID,
"api_id": apiId,

Check failure on line 330 in gateway/api.go

View workflow job for this annotation

GitHub Actions / Go 1.19.x Redis 5

undefined: apiId

Check failure on line 330 in gateway/api.go

View workflow job for this annotation

GitHub Actions / Go 1.19.x Redis 5

undeclared name: apiId

Check failure on line 330 in gateway/api.go

View workflow job for this annotation

GitHub Actions / Go 1.19.x Redis 5

undefined: apiId

Check failure on line 330 in gateway/api.go

View workflow job for this annotation

GitHub Actions / Go 1.19.x Redis 5

undeclared name: apiId
"user_id": "system",
"user_ip": "--",
"path": "--",
"server_name": "system",
}).Warn("API inactive or doesn't exist.")

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.

return errors.New("API must be active to add keys")
}

// reset API-level limit to empty APILimit if any has a zero-value
resetAPILimits(newSession.AccessRights)
// We have a specific list of access rules, only add / update those
for apiId := range newSession.AccessRights {
apiSpec := gw.getApiSpec(apiId)
if apiSpec == nil {
log.WithFields(logrus.Fields{
"prefix": "api",
"key": keyName,
"org_id": newSession.OrgID,
"api_id": apiId,
"user_id": "system",
"user_ip": "--",
"path": "--",
"server_name": "system",
}).Warn("API inactive or doesn't exist.")

apiSpec = &APISpec{
APIDefinition: &apidef.APIDefinition{
Expand Down

0 comments on commit 70de154

Please sign in to comment.