Skip to content
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

Parsing a Basic Authorization header fails if password contains ':' #3193

Open
camarena opened this issue Oct 23, 2024 · 0 comments
Open

Parsing a Basic Authorization header fails if password contains ':' #3193

camarena opened this issue Oct 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@camarena
Copy link

The method zio.http.Header.Authorization.parseBasic fails with Basic Authorization header value is not in the format username:password if the password contains a ':'. partsOfBasic.length will be greater than 2 in that case.

    private def parseBasic(value: String): Either[String, Authorization] = {
      try {
        val partsOfBasic = new String(Base64.getDecoder.decode(value)).split(":")
        if (partsOfBasic.length == 2) {
          Right(Basic(partsOfBasic(0), Secret(partsOfBasic(1))))
        } else {
          Left("Basic Authorization header value is not in the format username:password")
        }
      } catch {
        case _: IllegalArgumentException =>
          Left("Basic Authorization header value is not a valid base64 encoded string")
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant