我正在获取 JWKS从 https://X.auth0.com/.well-known/jwks.json
服务器端。我想知道将它们缓存几分钟是否安全,因为不断地用 gets 攻击那个端点似乎很浪费。
我正在使用 Flask 并计划通过做一些简单的事情来缓存它:
@cache.cached(timeout=60, key_prefix='auth0/%s')
def get_jwks():
return requests.get("https://" + AUTH0_DOMAIN + "/.well-known/jwks.json").json()
其余的实现很大程度上受到 auth0 tutorial 的启发。 .
缓存机制来自库flask_caching
,里面说:
You are able to use this decorator with any function by changing the
key_prefix
最佳答案
JWKS 是一个 Auth0 概念。它包含用于验证已发行 token 签名的公钥集
At the most basic level, the JWKS is a set of keys containing the public keys that should be used to verify any JWT issued by the authorization server.
可以安全地发布公钥。它只会在生成新的 key 对时发生变化。我不知道更新 key 的过程是怎样的:手动还是自动。但是你可以完美地缓存它。如果原因是错误的公钥,请确保在验证失败后下载公钥
关于python-3.x - 从 Auth0 对 JSON Web key 集 (JWKS) 进行服务器端 (python3/flask) 缓存一分钟左右是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47439842/