File tree Expand file tree Collapse file tree 1 file changed +26
-9
lines changed Expand file tree Collapse file tree 1 file changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -21,15 +21,16 @@ 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
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
3334 }{
3435 {
3536 desc : "Error: Query Values has 'error' key" ,
@@ -111,6 +112,15 @@ func TestServer(t *testing.T) {
111112 statusCode : 200 ,
112113 testTemplate : true ,
113114 },
115+ {
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 ,
123+ },
114124 }
115125
116126 for _ , test := range tests {
@@ -185,6 +195,13 @@ func TestServer(t *testing.T) {
185195 }
186196
187197 if test .testTemplate {
198+ if test .testHTMLInjection {
199+ if ! strings .Contains (string (content ), "<script>alert('this code snippet was executed')</script>" ) {
200+ t .Errorf ("TestServer(%s): want escaped html entities" , test .desc )
201+ }
202+ continue
203+ }
204+
188205 if len (test .errorPage ) > 0 {
189206 errCode := bytes .Contains (test .errorPage , []byte ("{{.Code}}" ))
190207 errDescription := bytes .Contains (test .errorPage , []byte ("{{.Err}}" ))
You can’t perform that action at this time.
0 commit comments