Handle wrong OIDC tokens gracefully

If you copy and paste only part of a token then a general DecodeError is
raised. It's the parent class for all other related errors like for
expired signatures.

Now we just fail authentication instead of raising a server error.
This commit is contained in:
Maikel Linke
2025-01-24 09:01:04 +11:00
parent 7b8b7b6bbc
commit 8636d3fc00
2 changed files with 7 additions and 1 deletions

View File

@@ -20,7 +20,7 @@ class AuthorizationControl
def user
oidc_user || ofn_api_user || ofn_user
rescue JWT::ExpiredSignature
rescue JWT::DecodeError
nil
end

View File

@@ -34,6 +34,12 @@ RSpec.describe AuthorizationControl do
expect(auth(oidc_token: token).user).to eq nil
end
it "ignores malformed tokens" do
token = "eyJhbGciOiJSUzI1NiIsInR5c"
expect(auth(oidc_token: token).user).to eq nil
end
end
describe "with OFN API token" do