Skip to content

Commit fc96d39

Browse files
committed
Update default error page XSS tests, to cover both the .Code and the .Err template fields
1 parent e44d1dc commit fc96d39

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

apps/internal/local/server_test.go

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ func TestServer(t *testing.T) {
2121
defer cancel()
2222

2323
tests := []struct {
24-
desc string
25-
reqState string
26-
port int
27-
q url.Values
28-
failPage bool
29-
statusCode int
30-
successPage []byte
31-
errorPage []byte
32-
testTemplate bool
33-
testHTMLInjection bool
24+
desc string
25+
reqState string
26+
port int
27+
q url.Values
28+
failPage bool
29+
statusCode int
30+
successPage []byte
31+
errorPage []byte
32+
testTemplate bool
33+
testErrCodeXSS bool
34+
testErrDescriptionXSS bool
3435
}{
3536
{
3637
desc: "Error: Query Values has 'error' key",
@@ -113,13 +114,22 @@ func TestServer(t *testing.T) {
113114
testTemplate: true,
114115
},
115116
{
116-
desc: "Error: Query Values missing 'state' key, using default fail error page - XSS test",
117-
reqState: "state",
118-
port: 0,
119-
q: url.Values{"error": []string{"<script>alert('this code snippet was executed')</script>"}, "error_description": []string{"error_description"}},
120-
statusCode: 200,
121-
testTemplate: true,
122-
testHTMLInjection: true,
117+
desc: "Error: Query Values missing 'state' key, using default fail error page - Error Code XSS test",
118+
reqState: "state",
119+
port: 0,
120+
q: url.Values{"error": []string{"<script>alert('this code snippet was executed')</script>"}, "error_description": []string{"error_description"}},
121+
statusCode: 200,
122+
testTemplate: true,
123+
testErrCodeXSS: true,
124+
},
125+
{
126+
desc: "Error: Query Values missing 'state' key, using default fail error page - Error Description XSS test",
127+
reqState: "state",
128+
port: 0,
129+
q: url.Values{"error": []string{"error_code"}, "error_description": []string{"<script>alert('this code snippet was executed')</script>"}},
130+
statusCode: 200,
131+
testTemplate: true,
132+
testErrDescriptionXSS: true,
123133
},
124134
}
125135

@@ -195,7 +205,7 @@ func TestServer(t *testing.T) {
195205
}
196206

197207
if test.testTemplate {
198-
if test.testHTMLInjection {
208+
if test.testErrCodeXSS || test.testErrDescriptionXSS {
199209
if !strings.Contains(string(content), "&lt;script&gt;alert(&#39;this code snippet was executed&#39;)&lt;/script&gt;") {
200210
t.Errorf("TestServer(%s): want escaped html entities", test.desc)
201211
}

0 commit comments

Comments
 (0)