Skip to content

Commit d0e2a29

Browse files
committed
fix: tos_uri validation
1 parent 41476ec commit d0e2a29

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

client/validator.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ func (v *Validator) Validate(ctx context.Context, c *Client) error {
8888
}
8989
}
9090

91+
if c.TermsOfServiceURI != "" {
92+
u, err := url.ParseRequestURI(c.TermsOfServiceURI)
93+
if err != nil {
94+
return errorsx.WithStack(ErrInvalidClientMetadata.WithHint("Field tos_uri must be a valid URI."))
95+
}
96+
97+
if u.Scheme != "https" && u.Scheme != "http" {
98+
return errorsx.WithStack(ErrInvalidClientMetadata.WithHintf("tos_uri %s must use https:// or http:// as HTTP scheme.", c.TermsOfServiceURI))
99+
}
100+
101+
}
102+
91103
if len(c.Secret) > 0 && len(c.Secret) < 6 {
92104
return errorsx.WithStack(ErrInvalidClientMetadata.WithHint("Field client_secret must contain a secret that is at least 6 characters long."))
93105
}

client/validator_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ func TestValidate(t *testing.T) {
3737
reg := internal.NewRegistryMemory(t, c, &contextx.Static{C: c.Source(ctx)})
3838
v := NewValidator(reg)
3939

40-
testCtx := context.TODO()
41-
4240
dec := json.NewDecoder(strings.NewReader(validJWKS))
4341
dec.DisallowUnknownFields()
4442
var goodJWKS jose.JSONWebKeySet
@@ -129,6 +127,10 @@ func TestValidate(t *testing.T) {
129127
assert.Equal(t, []string{"https://foo/"}, []string(c.PostLogoutRedirectURIs))
130128
},
131129
},
130+
{
131+
in: &Client{ID: "foo", TermsOfServiceURI: "javascript:alert('XSS')"},
132+
assertErr: assert.Error,
133+
},
132134
{
133135
in: &Client{ID: "foo"},
134136
check: func(t *testing.T, c *Client) {
@@ -163,7 +165,7 @@ func TestValidate(t *testing.T) {
163165
return v
164166
}
165167
}
166-
err := tc.v(t).Validate(testCtx, tc.in)
168+
err := tc.v(t).Validate(ctx, tc.in)
167169
if tc.assertErr != nil {
168170
tc.assertErr(t, err)
169171
} else {
@@ -179,7 +181,7 @@ type fakeHTTP struct {
179181
c *http.Client
180182
}
181183

182-
func (f *fakeHTTP) HTTPClient(ctx context.Context, opts ...httpx.ResilientOptions) *retryablehttp.Client {
184+
func (f *fakeHTTP) HTTPClient(_ context.Context, opts ...httpx.ResilientOptions) *retryablehttp.Client {
183185
c := httpx.NewResilientClient(opts...)
184186
c.HTTPClient = f.c
185187
return c
@@ -190,7 +192,7 @@ func TestValidateSectorIdentifierURL(t *testing.T) {
190192
var payload string
191193

192194
var h http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
193-
w.Write([]byte(payload))
195+
_, _ = w.Write([]byte(payload))
194196
}
195197
ts := httptest.NewTLSServer(h)
196198
defer ts.Close()

0 commit comments

Comments
 (0)