Skip to content

Valid email address should only start with alphanumeric #28174

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 10 commits into from
Apr 20, 2025

Conversation

dek5troza
Copy link
Contributor

This fixes issue #27847 where regular expression allowed email address to start with special symbols. Valid email addresses should start with alphanumeric character, and as such will be rendered as email.

Added test cases from the bug report to validate, such input will not be rendered anymore as email address.

Valid email addresses should start with alphanumeric character.
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 22, 2023
@lunny
Copy link
Member

lunny commented Nov 22, 2023

Could it start with a number?

Copy link
Member

@lng2020 lng2020 left a comment

Choose a reason for hiding this comment

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

I'm afraid it's not right. According to that issue, the correct test case should be

test(
  "[email protected]",
  `<p>?<a href="mailto:[email protected]" rel="nofollow">[email protected]</a></p>`
)

The expected behavior of that issue is ~ not rendered but [email protected] rendered.

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 23, 2023
@dek5troza
Copy link
Contributor Author

I'm afraid it's not right. According to that issue, the correct test case should be

test(
  "[email protected]",
  `<p>?<a href="mailto:[email protected]" rel="nofollow">[email protected]</a></p>`
)

The expected behavior of that issue is ~ not rendered but [email protected] rendered.

Ok, I misunderstood the issue. I ll give it another go. Thanks

dek5troza and others added 2 commits November 23, 2023 18:59
Regular expression will attempt to match valid portion of the email
which start with ~,* or ? or their combination.
@dek5troza
Copy link
Contributor Author

Ok, so hopefully I understood the issue this time. It should handle those characters in the way you have described to me in the comment. Let me know, if I need to update anything else, and I will do it.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Nov 28, 2023

According to RFC and Golang's mail.ParseAddress: *[email protected] [email protected] are all valid email addresses.

Although the old regexp doesn't look good, I do not see real benefit by introducing another incorrect (hacky?) patch.


Sorry, maybe I misunderstood the PR, will do more tests.

@techknowlogick techknowlogick changed the title Valid email address should only start with alphanumeric. Valid email address should only start with alphanumeric Nov 28, 2023
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Nov 28, 2023

Made a small change (remove the ? from regexp because it doesn't affect the result, there is no ? in regexp body) and added some test cases.

dek5troza#1 (not ideal enough, see below)


Well, I am still not sure whether we should really use this patch.

Test code:

func main() {
	a, _ := mail.ParseAddress("[email protected]")
	println(a.Address)
	a, _ = mail.ParseAddress("*[email protected]")
	println(a.Address)
}

Because [email protected] and *[email protected] are valid email addresses .......

@lng2020 lng2020 self-requested a review November 28, 2023 05:46
@lng2020 lng2020 added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Nov 28, 2023
@dek5troza
Copy link
Contributor Author

Made a small change (remove the ? from regexp because it doesn't affect the result, there is no ? in regexp body) and added some test cases.

dek5troza#1 (not ideal enough, see below)

Well, I am still not sure whether we should really use this patch.

Test code:

func main() {
	a, _ := mail.ParseAddress("[email protected]")
	println(a.Address)
	a, _ = mail.ParseAddress("*[email protected]")
	println(a.Address)
}

Because [email protected] and *[email protected] are valid email addresses .......

I was just going by @lng2020 comment. Technically those are valid by RFC5322 but it's arguable how usable those are, as most email service providers would not allow them with rules and filters.

If more changes are needed with this, I ll be happy to help and update.

@dek5troza
Copy link
Contributor Author

Hey guys, do you want me to update the patch, and separate ~something as valid email, or how would you like me to proceed with this?

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Dec 8, 2023

I do not have strong objection for the "arguable" RFC format. But there are still nits:

  1. I still think it needs to "remove the ? from regexp because it doesn't affect the result, there is no ? in regexp body".
  2. It needs more tests to show the behavior, especially the edge cases like a*a and a~a if they were not covered before.
  3. It needs more comments to describe the decision and the difference from the RFC.

@dek5troza
Copy link
Contributor Author

I do not have strong objection for the "arguable" RFC format. But there are still nits:

  1. I still think it needs to "remove the ? from regexp because it doesn't affect the result, there is no ? in regexp body".
  2. It needs more tests to show the behavior, especially the edge cases like a*a and a~a if they were not covered before.
  3. It needs more comments to describe the decision and the difference from the RFC.

Cool, I ll give it till Monday, if there are more opinions, and start updating on Monday with things you have listed above.

@karlwilbur
Copy link

karlwilbur commented Jan 18, 2025

I have worked with email validation before. I have a Ruby gem that does this. I am not suggesting that we try implementing a Ruby gem. 😆 But, maybe my work there might be helpful with sorting out validation and verification (tests of the validation code) within Gitea. Feel free to rip/refactor/repurpose as much of my code as you'd like:

https://rubygems.org/gems/email_validator
https://github.com/K-and-R/email_validator/blob/master/lib/email_validator.rb

I also have a pretty thorough set of tests:
https://github.com/K-and-R/email_validator/blob/master/spec/email_validator_spec.rb

I hope it helps!

@wxiaoguang
Copy link
Contributor

Inactive for long time, ping ~~

@wxiaoguang wxiaoguang added the issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail label Mar 13, 2025
@dek5troza
Copy link
Contributor Author

dek5troza commented Mar 13, 2025

Inactive for long time, ping ~~

You are right, this slipped through. I ll take a stab at it this weekend.

# Conflicts:
#	modules/markup/html.go
@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 20, 2025
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Apr 20, 2025
@GiteaBot GiteaBot added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Apr 20, 2025
@wxiaoguang wxiaoguang modified the milestones: 1.25.0, 1.24.0 Apr 20, 2025
@wxiaoguang wxiaoguang added type/bug and removed issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail labels Apr 20, 2025
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 20, 2025
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 20, 2025
@wxiaoguang wxiaoguang merged commit af6be75 into go-gitea:main Apr 20, 2025
26 checks passed
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 21, 2025
* giteaofficial/main:
  Add API routes to lock and unlock issues (go-gitea#34165)
  Make ROOT_URL support using request Host header (go-gitea#32564)
  Valid email address should only start with alphanumeric (go-gitea#28174)
  Fix notify watch failure when the content is too long (go-gitea#34233)
  Add "--fullname" arg to gitea admin user create (go-gitea#34241)
  Fix various UI problems (go-gitea#34243)
  markup: improve code block readability and isolate copy button (go-gitea#34009)
  Don't assume the default wiki branch is master in the wiki API (go-gitea#34244)
  [skip ci] Updated translations via Crowdin
  Optimize the calling code of queryElems (go-gitea#34235)
  Actions Runner rest api (go-gitea#33873)
  Fix some trivial problems (go-gitea#34237)
  Swift files can be passed either as file or as form value (go-gitea#34068)

# Conflicts:
#	templates/repo/wiki/revision.tmpl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants