Skip to content

Commit 313ce53

Browse files
authored
Use json tags to suppress Account fields in API responses (#8455)
Fixes #7774
1 parent 9392b44 commit 313ce53

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

core/objects.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type RawCertificateRequest struct {
9494
// to account keys.
9595
type Registration struct {
9696
// Unique identifier
97-
ID int64 `json:"id,omitempty"`
97+
ID int64 `json:"-"`
9898

9999
// Account key to which the details are attached
100100
Key *jose.JSONWebKey `json:"key"`
@@ -103,7 +103,7 @@ type Registration struct {
103103
Contact *[]string `json:"contact,omitempty"`
104104

105105
// Agreement with terms of service
106-
Agreement string `json:"agreement,omitempty"`
106+
Agreement string `json:"-"`
107107

108108
// CreatedAt is the time the registration was created.
109109
CreatedAt *time.Time `json:"createdAt,omitempty"`

wfe2/wfe.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,6 @@ func (wfe *WebFrontEndImpl) NewAccount(
768768
wfe.sendError(response, logEvent, probs.ServerInternal("Error marshaling account"), err)
769769
return
770770
}
771-
prepAccountForDisplay(&acct)
772771

773772
err = wfe.writeJsonResponse(response, logEvent, http.StatusOK, acct)
774773
if err != nil {
@@ -895,8 +894,6 @@ func (wfe *WebFrontEndImpl) NewAccount(
895894
response.Header().Add("Link", link(wfe.SubscriberAgreementURL, "terms-of-service"))
896895
}
897896

898-
prepAccountForDisplay(&acct)
899-
900897
err = wfe.writeJsonResponse(response, logEvent, http.StatusCreated, acct)
901898
if err != nil {
902899
// ServerInternal because we just created this account, and it
@@ -1197,24 +1194,6 @@ func (wfe *WebFrontEndImpl) Challenge(
11971194
}
11981195
}
11991196

1200-
// prepAccountForDisplay takes a core.Registration and mutates it to be ready
1201-
// for display in a JSON response. Primarily it papers over legacy ACME v1
1202-
// features or non-standard details internal to Boulder we don't want clients to
1203-
// rely on.
1204-
func prepAccountForDisplay(acct *core.Registration) {
1205-
// Zero out the account ID so that it isn't marshalled. RFC 8555 specifies
1206-
// using the Location header for learning the account ID.
1207-
acct.ID = 0
1208-
1209-
// We populate the account Agreement field when creating a new response to
1210-
// track which terms-of-service URL was in effect when an account with
1211-
// "termsOfServiceAgreed":"true" is created. That said, we don't want to send
1212-
// this value back to a V2 client. The "Agreement" field of an
1213-
// account/registration is a V1 notion so we strip it here in the WFE2 before
1214-
// returning the account.
1215-
acct.Agreement = ""
1216-
}
1217-
12181197
// prepChallengeForDisplay takes a core.Challenge and prepares it for display to
12191198
// the client by filling in its URL field and clearing several unnecessary
12201199
// fields.
@@ -1432,8 +1411,6 @@ func (wfe *WebFrontEndImpl) Account(
14321411
response.Header().Add("Link", link(wfe.SubscriberAgreementURL, "terms-of-service"))
14331412
}
14341413

1435-
prepAccountForDisplay(acct)
1436-
14371414
err = wfe.writeJsonResponse(response, logEvent, http.StatusOK, acct)
14381415
if err != nil {
14391416
wfe.sendError(response, logEvent, probs.ServerInternal("Failed to marshal account"), err)
@@ -1994,7 +1971,6 @@ func (wfe *WebFrontEndImpl) KeyRollover(
19941971
wfe.sendError(response, logEvent, probs.ServerInternal("Error marshaling proto to registration"), err)
19951972
return
19961973
}
1997-
prepAccountForDisplay(&updatedAcct)
19981974

19991975
err = wfe.writeJsonResponse(response, logEvent, http.StatusOK, updatedAcct)
20001976
if err != nil {

wfe2/wfe_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,19 +3779,30 @@ func TestOrderToOrderJSONV2Authorizations(t *testing.T) {
37793779
})
37803780
}
37813781

3782-
func TestPrepAccountForDisplay(t *testing.T) {
3782+
func TestAccountMarshaling(t *testing.T) {
37833783
acct := &core.Registration{
37843784
ID: 1987,
37853785
Agreement: "disagreement",
3786+
Status: core.StatusValid,
37863787
}
37873788

3788-
// Prep the account for display.
3789-
prepAccountForDisplay(acct)
3789+
marshaled, err := json.Marshal(acct)
3790+
if err != nil {
3791+
t.Fatalf("marshalling account object: %s", err)
3792+
}
3793+
3794+
var got core.Registration
3795+
err = json.Unmarshal(marshaled, &got)
3796+
if err != nil {
3797+
t.Fatalf("unmarshaling account object: %s", err)
3798+
}
37903799

37913800
// The Agreement should always be cleared.
3792-
test.AssertEquals(t, acct.Agreement, "")
3801+
test.AssertEquals(t, got.Agreement, "")
37933802
// The ID field should be zeroed.
3794-
test.AssertEquals(t, acct.ID, int64(0))
3803+
test.AssertEquals(t, got.ID, int64(0))
3804+
// The Status field should be preserved.
3805+
test.AssertEquals(t, got.Status, core.StatusValid)
37953806
}
37963807

37973808
// TestGet404 tests that a 404 is served and that the expected endpoint of

0 commit comments

Comments
 (0)