ra: forbid mailto contacts that contain hfields (#4694)

https://tools.ietf.org/html/rfc8555#section-7.3

   Clients MUST NOT
   provide a "mailto" URL in the "contact" field that contains "hfields"
   [RFC6068] or more than one "addr-spec" in the "to" component.  If a
   server encounters a "mailto" contact URL that does not meet these
   criteria, then it SHOULD reject it as invalid.
This commit is contained in:
alexzorin 2020-03-12 11:15:23 +11:00 committed by GitHub
parent 2bf12b93e1
commit 0dd8f41c1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -358,6 +358,7 @@ func (ra *RegistrationAuthorityImpl) NewRegistration(ctx context.Context, init c
// * A list containing an empty contact
// * A list containing a contact that does not parse as a URL
// * A list containing a contact that has a URL scheme other than mailto
// * A list containing a mailto contact that contains hfields
// * A list containing a contact that has non-ascii characters
// * A list containing a contact that doesn't pass `validateEmail`
func (ra *RegistrationAuthorityImpl) validateContacts(ctx context.Context, contacts *[]string) error {
@ -383,6 +384,9 @@ func (ra *RegistrationAuthorityImpl) validateContacts(ctx context.Context, conta
if parsed.Scheme != "mailto" {
return berrors.InvalidEmailError("contact method %q is not supported", parsed.Scheme)
}
if parsed.RawQuery != "" {
return berrors.InvalidEmailError("contact email [%q] contains hfields", contact)
}
if !core.IsASCII(contact) {
return berrors.InvalidEmailError(
"contact email [%q] contains non-ASCII characters",

View File

@ -419,6 +419,9 @@ func TestValidateContacts(t *testing.T) {
err = ra.validateContacts(context.Background(), &[]string{"mailto:admin@[1.2.3.4]"})
test.AssertError(t, err, "Forbidden email")
err = ra.validateContacts(context.Background(), &[]string{"mailto:admin@a.com?no-reminder-emails"})
test.AssertError(t, err, "No hfields in email")
// The registrations.contact field is VARCHAR(191). 175 'a' characters plus
// the prefix "mailto:" and the suffix "@a.com" makes exactly 191 bytes of
// encoded JSON. The correct size to hit our maximum DB field length.