Skip to content

JWKMatcher issues with ids #120

@ghost

Description

I had some issues while trying to use JWKMatcher. I have a failing unit test at https://github.com/axtsnee/scala-jwk/blob/main/library/src/test/scala/com/chatwork/scala/jwk/JWKMatcherSpec.scala that illustrates the problem. If I create a JWKMatcher with a set of one ID, it's matches method will return true even for JWKs with different IDs.

The problem seems to be on lines 43-44 of JWKMatcher.scala.

else if (ids.nonEmpty && ids.exists(v => key.keyId.contains(v)))
  Right(false)

v is of type String, and key.keyId is of type Option[com.chatwork.scala.jwk.KeyId]. Since a String can never be equal to a KeyId, key.keyId.contains(v) is always false, so this check is effectively always skipped. Maybe those lines should look more like this:

else if (hasId && ids.forall(v => !key.keyId.exists(_.value == v)))
  Right(false)

Just looking at the JWKMatcher code, I see some other potential problems. For instance, if line 38 evaluates to true, matches returns true immediately, without making any of the checks on lines 41 - 58.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions