Skip to content

Commit

Permalink
Verify that the JWKS is not empty before verifying signature
Browse files Browse the repository at this point in the history
Otherwise, an unsigned JWT will validate against a nil jwks
  • Loading branch information
segiddins committed Feb 9, 2024
1 parent a3467f8 commit 36c7ab2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/v1/oidc/api_key_roles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def set_api_key_role
end

def decode_jwt
raise UnverifiedJWT, "Provider missing JWKS" if @api_key_role.provider.jwks.blank?
@jwt = JSON::JWT.decode_compact_serialized(params.require(:jwt), @api_key_role.provider.jwks)
rescue JSON::ParserError
raise UnverifiedJWT, "Invalid JSON"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def find_provider
end

def verify_signature
raise UnsupportedIssuer, "Provider is missing jwks" if @provider.jwks.blank?
raise UnverifiedJWT, "Invalid time" unless (@jwt["nbf"]..@jwt["exp"]).cover?(Time.now.to_i)
@jwt.verify!(@provider.jwks)
end
Expand Down
16 changes: 16 additions & 0 deletions test/integration/api/v1/oidc/trusted_publisher_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ def jwt(claims = @claims, key: @pkey)
assert_response :not_found
end

should "return not found when issuer has no jwks and jwt is unsigned" do
trusted_publisher = build(:oidc_trusted_publisher_github_action,
repository_name: "oidc-test",
repository_owner_id: "1946610",
workflow_filename: "token.yml")
trusted_publisher.repository_owner = "segiddins"
trusted_publisher.save!

OIDC::Provider.github_actions.update!(jwks: nil)

post api_v1_oidc_trusted_publisher_exchange_token_path,
params: { jwt: JSON::JWT.new(@claims).to_s }

assert_response :not_found
end

should "succeed with matching trusted publisher" do
trusted_publisher = build(:oidc_trusted_publisher_github_action,
repository_name: "oidc-test",
Expand Down

0 comments on commit 36c7ab2

Please sign in to comment.