Skip to content

Commit eb68d90

Browse files
committed
Adding option to disable negative cache
1 parent 03ec1d3 commit eb68d90

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,19 @@ from the cache. In order to avoid cache confusion it is recommended to
384384
set `opts.cache_segment` to unique strings for each set of related
385385
locations.
386386

387+
## Caching of negative Introspection responses
388+
389+
By default `introspection` cache will not store negative responses.
390+
This means that bad actor can potentialy try to exhaust introspection
391+
endpoint by flooding service with a lot of calls with inproper token.
392+
To prevent this situation `opts.introspection_enable_negative_cache`
393+
can be set to `true`. This will enable `introspection` cache to store
394+
negative responses for time defined in `exp` field.
395+
Caching negative introspection responses will offload traffic from
396+
introspection endpoint but also will expose NGINX for resource exhaustion
397+
attacks as storing negative introspection responses will use extra
398+
cache storage.
399+
387400
## Revoke tokens
388401

389402
The `revoke_tokens(opts, session)` function revokes the current refresh and access token. In contrast to a full logout, the session cookie will not be destroyed and the endsession endpoint will not be called. The function returns `true` if both tokens were revoked successfully. This function might be helpful in scenarios where you want to destroy/remove a session from the server side.

lib/resty/openidc.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,13 @@ function openidc.introspect(opts)
18191819
return json, err
18201820
end
18211821

1822+
-- check if negative cache should be in use
1823+
local introspection_enable_negative_cache = opts.introspection_enable_negative_cache or false
1824+
if not json.active and not introspection_enable_negative_cache then
1825+
err = "invalid token"
1826+
return json, err
1827+
end
1828+
18221829
-- cache the results
18231830
local introspection_cache_ignore = opts.introspection_cache_ignore or false
18241831
local expiry_claim = opts.introspection_expiry_claim or "exp"

0 commit comments

Comments
 (0)