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

Fix compatibility problem with aliyun and netease mail as authentication source #27044

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

darren
Copy link

@darren darren commented Sep 12, 2023

Close #27043

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 12, 2023
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Sep 12, 2023
routers/web/auth/auth.go Outdated Show resolved Hide resolved
@lunny lunny added type/bug backport/v1.20 This PR should be backported to Gitea 1.20 labels Sep 13, 2023
@lunny lunny added this to the 1.21.0 milestone Sep 13, 2023
@darren darren changed the title Show error instead of HTTP status 500 if authenticate fails via external SMTP fix compatibility problem while using aliyun mail as authentication source Sep 16, 2023
@pull-request-size pull-request-size bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 16, 2023
@darren
Copy link
Author

darren commented Sep 16, 2023

@lunny @puni9869

I have modified the original issue title and make changes to this pull request, can you re-review this?
this is the original code that handles smtp auth error

if (ok && tperr.Code == 535) ||
strings.Contains(err.Error(), "Username and Password not accepted") {
return nil, user_model.ErrUserNotExist{Name: userName}
}
if (ok && tperr.Code == 534) ||
strings.Contains(err.Error(), "Application-specific password required") {
return nil, user_model.ErrUserNotExist{Name: userName}
}
return nil, err

it only handles specific textproto error, so it may have compatibility with different email providers. and the actual textproto error is hidden from the log.

with this pr, when auth fails it shows error in log like this(aliyun mail)

2023/09/16 10:13:01 ...ers/web/auth/auth.go:206:SignInPost() [I] Failed authentication attempt for xxx@xxx.com from 127.0.0.1:11919: invalid argument
526 Authentication failure[0]

@darren darren changed the title fix compatibility problem while using aliyun mail as authentication source fix compatibility problem with aliyun mail as authentication source Sep 16, 2023
@darren darren changed the title fix compatibility problem with aliyun mail as authentication source fix compatibility problem with aliyun and netease mail as authentication source Sep 16, 2023
@darren darren changed the title fix compatibility problem with aliyun and netease mail as authentication source Fix compatibility problem with aliyun and netease mail as authentication source Sep 16, 2023
@puni9869
Copy link
Member

Will take a look tomorrow.

@lunny
Copy link
Member

lunny commented Sep 19, 2023

It's not easy if we have no accounts of that two platforms.

@darren
Copy link
Author

darren commented Sep 19, 2023

It's not easy if we have no accounts of that two platforms.

Actually you don't have to have accounts of these email providers, Just setup an SMTP authentication source with smtp.qiye.aliyun.com as host. And do login with any email account, the 500 error will show up.

@lunny lunny modified the milestones: 1.21.0, 1.22.0 Sep 21, 2023
@yp05327
Copy link
Contributor

yp05327 commented Apr 10, 2024

If I understand correctly, 526 error is caused by DNS error?
https://www.alibabacloud.com/help/en/direct-mail/user-guide/summary-of-common-email-return-codes-and-solutions
image

Maybe this one:
https://www.alibabacloud.com/help/en/alibaba-mail/latest/526-authentication-failure
From this doc, 526 error is not only caused by incorrect username/password error, but also incorrect server address.

ps: What I want to say is that, this is not a normal error code for smtp authentication error, so we need docs to explain why we need to do this.

@darren
Copy link
Author

darren commented Apr 10, 2024

If I understand correctly, 526 error is caused by DNS error? https://www.alibabacloud.com/help/en/direct-mail/user-guide/summary-of-common-email-return-codes-and-solutions image

Maybe this one: https://www.alibabacloud.com/help/en/alibaba-mail/latest/526-authentication-failure

What I want to say is that, this is not a normal error code for smtp authentication error, so we need docs to explain why we need to do this.

As I have commented in the PR:

	// when authentication via smtp fails, wraps ErrInvalidArgument
	// with the original textproto.Error as the cause,
	// so it will show username_password_incorrect to the user
	// while log the original error so that admin can check.
	// see: routers/web/auth/auth.go SiginPost

Is that clear enough to you ?

What this PR does is that instead of showing 500 to end user when such errors occurs, just show login failure to user and let admin to check the log to pinpoint the actual reason while not hiding it.

It's not perfect though, but still be better.

@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Apr 10, 2024
@yp05327
Copy link
Contributor

yp05327 commented Apr 10, 2024

I prefer adjusting the logic in UserSignIn and the error handling logic in SignInPost, as not all errors mean incorrect username/password.
For example, do not always show 500 error page, just show error info to users, like there's an unexpected error occurred during the login process, please contact the admin.

And maybe not related, the error handling logic for UserSignIn is checking ErrNotExist to detect whether user is existed, but it not only contains user not found error, but also some other errors, e.g. host not found.
Then you can see this, a white screen with nothing.
bug

@yp05327
Copy link
Contributor

yp05327 commented Apr 25, 2024

@lunny
maybe backport label should be changed? This PR has been moved to 1.22 milestone.

@lunny lunny modified the milestones: 1.22.0, 1.23.0 Apr 28, 2024
@lunny lunny added backport/v1.22 This PR should be backported to Gitea 1.22 and removed backport/v1.20 This PR should be backported to Gitea 1.20 labels Apr 28, 2024
@lunny lunny modified the milestones: 1.23.0, 1.24.0 Oct 9, 2024
@lunny lunny removed the backport/v1.22 This PR should be backported to Gitea 1.22 label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/go Pull requests that update Go code size/S Denotes a PR that changes 10-29 lines, ignoring generated files. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

compatibility problem while using aliyun mail as authentication source
6 participants