Skip to content

Fix code err code 401 when the password is empty in base_auth. #958

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

Merged
merged 1 commit into from
Jun 11, 2021

Conversation

CncGpp
Copy link
Contributor

@CncGpp CncGpp commented Jun 10, 2021

Fix: When setting the base_auth with a non-empty username and an empty password no auth is insert in the header.
The problem is similar to #650 but for the password.

@yhirose
Copy link
Owner

yhirose commented Jun 10, 2021

@CncGpp, thanks for the pull request, but it looks dangerous to accept blank password... RFC 7613 4.1 says:

A password MUST NOT be zero bytes in length. This rule is to be
enforced after any normalization and mapping of code points.

As you mentioned in #650, I made a change to allow username to be blank, since it looks a pretty common practice by popular servers. But I am not sure that the same thing can apply to password. Please give me more information why you really need it, or what servers are really allowing it. Thanks!

@CncGpp
Copy link
Contributor Author

CncGpp commented Jun 10, 2021

I'm using cpp-httplib to implement a basic client for ArangoDB (HTTP API), the DB password can be empty.

@yhirose
Copy link
Owner

yhirose commented Jun 10, 2021

@PixlRainbow, what do you think about this pull request?

@PixlRainbow
Copy link
Contributor

I've looked into it; this should handle the case where a password needs to be sent that is blank. However, I found that certain servers may need the password field to be not present (not sent at all). But if your use case only requires the first case, then OK.

I would recommend however to use XOR instead of OR since we might not want to send basic auth header if both username and password are unset.

@yhirose
Copy link
Owner

yhirose commented Jun 11, 2021

@CncGpp, could you respond the comment from @PixlRainbow?

@CncGpp
Copy link
Contributor Author

CncGpp commented Jun 11, 2021

Sorry for the delay, wouldn't using XOR break the case where both userand pass are set? I think the OR is fine, when they are both empty it does not enter the if.

@PixlRainbow
Copy link
Contributor

ahh my bad, I had mistaken the conditions backwards :D

@yhirose yhirose merged commit ba82408 into yhirose:master Jun 11, 2021
@yhirose
Copy link
Owner

yhirose commented Jun 11, 2021

Thanks for the replies. I just merged it. Thanks for the contribution!

@CncGpp CncGpp deleted the new_branch branch June 12, 2021 09:09
ExclusiveOrange pushed a commit to ExclusiveOrange/cpp-httplib-exor that referenced this pull request May 2, 2023
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.

3 participants