Skip to content

Commit ef955a5

Browse files
authored
wfe: reject empty identifiers in new-authz and new-order (letsencrypt#5089)
Currently these are rejected at the RA. It's nicer to reject them one step earlier. Fixes letsencrypt#5081
1 parent 6f14be8 commit ef955a5

File tree

4 files changed

+82
-5
lines changed

4 files changed

+82
-5
lines changed

wfe/wfe.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,17 +742,34 @@ func (wfe *WebFrontEndImpl) NewAuthorization(ctx context.Context, logEvent *web.
742742
return
743743
}
744744

745-
var init core.Authorization
746-
if err := json.Unmarshal(body, &init); err != nil {
745+
var newAuthzRequest struct {
746+
Identifier struct {
747+
Type string
748+
Value string
749+
}
750+
}
751+
if err := json.Unmarshal(body, &newAuthzRequest); err != nil {
747752
wfe.sendError(response, logEvent, probs.Malformed("Error unmarshaling JSON"), err)
748753
return
749754
}
750-
if init.Identifier.Type == identifier.DNS {
751-
logEvent.DNSName = init.Identifier.Value
755+
if newAuthzRequest.Identifier.Type == "" || newAuthzRequest.Identifier.Value == "" {
756+
wfe.sendError(response, logEvent, probs.Malformed("Invalid new-authorization request: missing fields"), nil)
757+
return
758+
}
759+
if newAuthzRequest.Identifier.Type == string(identifier.DNS) {
760+
logEvent.DNSName = newAuthzRequest.Identifier.Value
761+
} else {
762+
wfe.sendError(response, logEvent, probs.Malformed("Invalid new-authorization request: wrong identifier type"), nil)
763+
return
752764
}
753765

754766
// Create new authz and return
755-
authz, err := wfe.RA.NewAuthorization(ctx, init, currReg.ID)
767+
authz, err := wfe.RA.NewAuthorization(ctx, core.Authorization{
768+
Identifier: identifier.ACMEIdentifier{
769+
Type: identifier.DNS,
770+
Value: newAuthzRequest.Identifier.Value,
771+
},
772+
}, currReg.ID)
756773
if err != nil {
757774
wfe.sendError(response, logEvent, web.ProblemDetailsForError(err, "Error creating new authz"), err)
758775
return

wfe/wfe_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,57 @@ func TestAuthorization500(t *testing.T) {
17751775

17761776
}
17771777

1778+
func TestNewAuthorizationEmptyDomain(t *testing.T) {
1779+
responseWriter := httptest.NewRecorder()
1780+
wfe, _ := setupWFE(t)
1781+
1782+
wfe.NewAuthorization(ctx, newRequestEvent(), responseWriter,
1783+
makePostRequest(signRequest(t, `{
1784+
"resource":"new-authz",
1785+
"identifier": {
1786+
"Type": "dns",
1787+
"Value": ""
1788+
}
1789+
}`, wfe.nonceService)))
1790+
test.AssertUnmarshaledEquals(t,
1791+
responseWriter.Body.String(),
1792+
`{"type":"`+probs.V1ErrorNS+`malformed","detail":"Invalid new-authorization request: missing fields","status":400}`)
1793+
}
1794+
1795+
func TestNewAuthorizationEmptyType(t *testing.T) {
1796+
responseWriter := httptest.NewRecorder()
1797+
wfe, _ := setupWFE(t)
1798+
1799+
wfe.NewAuthorization(ctx, newRequestEvent(), responseWriter,
1800+
makePostRequest(signRequest(t, `{
1801+
"resource":"new-authz",
1802+
"identifier": {
1803+
"Type": "",
1804+
"Value": "example.com"
1805+
}
1806+
}`, wfe.nonceService)))
1807+
test.AssertUnmarshaledEquals(t,
1808+
responseWriter.Body.String(),
1809+
`{"type":"`+probs.V1ErrorNS+`malformed","detail":"Invalid new-authorization request: missing fields","status":400}`)
1810+
}
1811+
1812+
func TestNewAuthorizationNonDNS(t *testing.T) {
1813+
responseWriter := httptest.NewRecorder()
1814+
wfe, _ := setupWFE(t)
1815+
1816+
wfe.NewAuthorization(ctx, newRequestEvent(), responseWriter,
1817+
makePostRequest(signRequest(t, `{
1818+
"resource":"new-authz",
1819+
"identifier": {
1820+
"Type": "shibboleth",
1821+
"Value": "example.com"
1822+
}
1823+
}`, wfe.nonceService)))
1824+
test.AssertUnmarshaledEquals(t,
1825+
responseWriter.Body.String(),
1826+
`{"type":"`+probs.V1ErrorNS+`malformed","detail":"Invalid new-authorization request: wrong identifier type","status":400}`)
1827+
}
1828+
17781829
func TestAuthorization(t *testing.T) {
17791830
wfe, _ := setupWFE(t)
17801831
mux := wfe.Handler(metrics.NoopRegisterer)

wfe2/wfe.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,10 @@ func (wfe *WebFrontEndImpl) NewOrder(
19701970
nil)
19711971
return
19721972
}
1973+
if ident.Value == "" {
1974+
wfe.sendError(response, logEvent, probs.Malformed("NewOrder request included empty domain name"), nil)
1975+
return
1976+
}
19731977
names[i] = ident.Value
19741978
}
19751979

wfe2/wfe_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,11 @@ func TestNewOrder(t *testing.T) {
22322232
Request: signAndPost(t, targetPath, signedURL, "foo", 1, wfe.nonceService),
22332233
ExpectedBody: `{"type":"` + probs.V2ErrorNS + `malformed","detail":"Request payload did not parse as JSON","status":400}`,
22342234
},
2235+
{
2236+
Name: "POST, empty domain name identifier",
2237+
Request: signAndPost(t, targetPath, signedURL, `{"identifiers":[{"type":"dns","value":""}]}`, 1, wfe.nonceService),
2238+
ExpectedBody: `{"type":"` + probs.V2ErrorNS + `malformed","detail":"NewOrder request included empty domain name","status":400}`,
2239+
},
22352240
{
22362241
Name: "POST, no identifiers in payload",
22372242
Request: signAndPost(t, targetPath, signedURL, "{}", 1, wfe.nonceService),

0 commit comments

Comments
 (0)