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

Basic authentication fails if realm is single quoted and has a blank in the value #6743

Closed
SailReal opened this issue Jul 4, 2021 · 6 comments
Labels
bug Bug in existing code

Comments

@SailReal
Copy link

SailReal commented Jul 4, 2021

Using Cryptomator for Android, we stumbled over the following problem: Davros server does respond with an single quoted basic realm: "WWW-Authenticate: Basic realm='Sandstorm API'". This together with the fact, that the realm has a blank in the value, leads to not creating a challange in HttpHeaders.Buffer.readChallengeHeader()

Using OkHttp "WWW-Authenticate: Basic realm=\"Sandstorm API\"" and "WWW-Authenticate: Basic realm='SandstormAPI'" works but "WWW-Authenticate: Basic realm='Sandstorm API'" not.

As also mentioned in mnutt/davros#74 (comment), RFC7617#section-2 only says that it can be a quoted string with the example "WallyWorld". I just tested it with a list of common WebDAV servers which all responds with the double quoted variant. But other clients also accepts blanks in single quoted string. So I really don't know exactly which party I should ask to fix this as also mentioned in mnutt/davros#74 (comment).

The easiest way to reproduce it, is to add those two tests to HeadersTest.java:

  // works
  @Test public void basicSingleQuoteNoBlankChallenge() {
    Headers headers = new Headers.Builder()
            .add("WWW-Authenticate: Basic realm='protected'")
            .build();
    assertThat(HttpHeaders.parseChallenges(headers, "WWW-Authenticate")).isEqualTo(
            singletonList(new Challenge("Basic", singletonMap("realm", "'protected'"))));
  }

  // fails
  @Test public void basicSingleQuoteWithBlankChallenge() {
    Headers headers = new Headers.Builder()
            .add("WWW-Authenticate: Basic realm='protected area'")
            .build();
    assertThat(HttpHeaders.parseChallenges(headers, "WWW-Authenticate")).isEqualTo(
            singletonList(new Challenge("Basic", singletonMap("realm", "'protected area'"))));
  }
@SailReal SailReal added the bug Bug in existing code label Jul 4, 2021
@yschimke
Copy link
Collaborator

yschimke commented Jul 4, 2021

I think given the ambiguity and risk of breaking existing behaviour, we'd be more inclined to change this given examples from Web Browsers e.g. Chrome or Firefox. What do they do?

@SailReal
Copy link
Author

SailReal commented Jul 4, 2021

What do they do?

Firefox and curl allows blanks in single quoted realm values.

According to the RFC, a blank is allowed in the value of the realm. From my point of view, the RFC does not specify whether it has to be double quotes or it can be single quotes as well, but a blank is explicitly allowed. In my opinion, if OkHttp already supports single quotes in general, blanks in single quotes should be supported too.

@yschimke
Copy link
Collaborator

yschimke commented Jul 4, 2021

I think technically that's covered here https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6

3.2.6.  Field Value Components

   Most HTTP header field values are defined using common syntax
   components (token, quoted-string, and comment) separated by
   whitespace or specific delimiting characters.  Delimiters are chosen
   from the set of US-ASCII visual characters not allowed in a token
   (DQUOTE and "(),/:;<=>?@[\]{}").

     token          = 1*tchar

     tchar          = "!" / "#" / "$" / "%" / "&" / "'" / "*"
                    / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
                    / DIGIT / ALPHA
                    ; any VCHAR, except delimiters

   A string of text is parsed as a single value if it is quoted using
   double-quote marks.

     quoted-string  = DQUOTE *( qdtext / quoted-pair ) DQUOTE
     qdtext         = HTAB / SP /%x21 / %x23-5B / %x5D-7E / obs-text
     obs-text       = %x80-FF

@SailReal
Copy link
Author

SailReal commented Jul 4, 2021

I think technically that's covered here https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6

Ah nice, thanks 👍, that sounds very clear but still raises the question why single quotes in general are supported but blanks in single quotes not 🤔.

@yschimke
Copy link
Collaborator

yschimke commented Jul 4, 2021

Yeah, I don't know the answer here. But at least for headers double quotes are "quotes" I believe.

@yschimke
Copy link
Collaborator

Going to close this given it's outside spec, and I'd be nervous about breaking current behaviour. I doubt we will fix based on the rare occurence here.

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

No branches or pull requests

2 participants