Skip to content

Raise an error when JWK::Set::Fetcher fetches something that's not a JWKS #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

moskyb
Copy link

@moskyb moskyb commented May 27, 2025

When using the JSON::JWK::Set::Fetcher, if a JWKS endpoint returns nothing but a string in double quotes, the contents of those double quotes will be interpreted as a symmetric JWK. As a minimal reproduction:

  1. In one terminal, run:
# Basic web server on port 8080 that returns "hello" (in double quotes), and nothing else
$ ruby -e 'require "socket";s=TCPServer.new 8080;loop{c=s.accept;c.gets;c.print "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 7\r\n\r\n\"hello\"";c.close}'
  1. in another terminal, in a pry shell, run:
JSON::JWK::Set::Fetcher.fetch("http://localhost:8080/", kid: nil, auto_detect: false)
# => [{"k" => "hello", "kty" => :oct, "kid" => "c9QtoFTsKPgH6ou94elR1Qgu_yCWUeWEG0dAG-TZWV8"}]

This is pretty unexpected behaviour, but it's also a little worrying in that the RFC enforces that JWKSes have a certain format, but also in that advanced attackers could potentially force a key verification to use a symmetric key that they control.

So, with all that said, this PR makes the JWK::Set::Fetcher do a sense check or two on the structure of the JWKSes it fetches -- basically just ensuring that they're hashes, that they have a keys key, and that the value of keys is an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant