Skip to content

Commit 73e8f1d

Browse files
committed
Add option error page XSS tests, to cover both the .Code and the .Err template fields
1 parent fc96d39 commit 73e8f1d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

apps/internal/local/server_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,26 @@ func TestServer(t *testing.T) {
131131
testTemplate: true,
132132
testErrDescriptionXSS: true,
133133
},
134+
{
135+
desc: "Error: Query Values missing 'state' key, using optional fail error page - Error Code XSS test",
136+
reqState: "state",
137+
port: 0,
138+
q: url.Values{"error": []string{"<script>alert('this code snippet was executed')</script>"}, "error_description": []string{"error_description"}},
139+
statusCode: 200,
140+
errorPage: []byte("error: {{.Code}} error_description: {{.Err}}"),
141+
testTemplate: true,
142+
testErrCodeXSS: true,
143+
},
144+
{
145+
desc: "Error: Query Values missing 'state' key, using optional fail error page - Error Description XSS test",
146+
reqState: "state",
147+
port: 0,
148+
q: url.Values{"error": []string{"error_code"}, "error_description": []string{"<script>alert('this code snippet was executed')</script>"}},
149+
statusCode: 200,
150+
errorPage: []byte("error: {{.Code}} error_description: {{.Err}}"),
151+
testTemplate: true,
152+
testErrDescriptionXSS: true,
153+
},
134154
}
135155

136156
for _, test := range tests {
@@ -212,6 +232,13 @@ func TestServer(t *testing.T) {
212232
continue
213233
}
214234

235+
if len(test.errorPage) > 0 && (test.testErrCodeXSS || test.testErrDescriptionXSS) {
236+
if !strings.Contains(string(content), "&lt;script&gt;alert(&#39;this code snippet was executed&#39;)&lt;/script&gt;") {
237+
t.Errorf("TestServer(%s): want escaped html entities", test.desc)
238+
}
239+
continue
240+
}
241+
215242
if len(test.errorPage) > 0 {
216243
errCode := bytes.Contains(test.errorPage, []byte("{{.Code}}"))
217244
errDescription := bytes.Contains(test.errorPage, []byte("{{.Err}}"))

0 commit comments

Comments
 (0)