Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Interactive Auth: Return 401 from for incorrect password #1160

Merged
merged 1 commit into from
Oct 7, 2016

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Oct 6, 2016

This requires a bit of fettling, because I want to return a helpful error
message too but we don't want to distinguish between unknown user and invalid
password. To avoid hardcoding the error message into 15 places in the code,
I've had to refactor a few methods to return None instead of throwing.

Fixes https://matrix.org/jira/browse/SYN-744

This requires a bit of fettling, because I want to return a helpful error
message too but we don't want to distinguish between unknown user and invalid
password. To avoid hardcoding the error message into 15 places in the code,
I've had to refactor a few methods to return None instead of throwing.

Fixes https://matrix.org/jira/browse/SYN-744
raise LoginError(
403, "Invalid password",
errcode=Codes.FORBIDDEN
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much as I don't want to go further down this refactoring rabbit hole, it would be nice to move this up one more layer so this function returned None or raise a sane error, and contain the 403 code to validate_password_login which is used for login and login only. wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try that. The thing is that, whatever error code _check_password_auth puts in its exception, check_auth is going to throw it away and turn it into a 401. So I'm not sure that's any clearer.

I started wondering what the point of LoginError actually is, and why it's different to SynapseError, and why it lets you set the http code rather than leaving that to a higher layer, and then I decided to stop thinking about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the fact that check_auth will clobber it with a 401 anyway is why I thought it might be clearer to use an exception without a specific code, so it's then catching an specific exception and turning it into one the upper layer understands, rather than catching the 403 exception and replacing the code. If you see it throwing the 403 error, it's surprising when that's re-caught, but less surprising if it's, say, AuthCheckException. I don't really hugely bothered though, either way this is an improvement over what was there before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see the problem: the different auth checkers all throw LoginError, so you'd have to change all of them. Yeah, ok - it's not worth it.

@richvdh
Copy link
Member Author

richvdh commented Oct 7, 2016

@matrixbot: retest this please

@richvdh richvdh merged commit 8681aff into develop Oct 7, 2016
@richvdh richvdh deleted the rav/401_on_password_fail branch October 7, 2016 15:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants