@@ -222,8 +222,9 @@ func TestDeviceCallback(t *testing.T) {
222222 code : "somecode" ,
223223 error : "Error Condition" ,
224224 },
225- expectedResponseCode : http .StatusBadRequest ,
226- expectedServerResponse : "Error Condition: \n " ,
225+ expectedResponseCode : http .StatusBadRequest ,
226+ // Note: Error details should NOT be displayed to user anymore.
227+ // Instead, a safe generic message is shown.
227228 },
228229 {
229230 testName : "Expired Auth Code" ,
@@ -352,8 +353,9 @@ func TestDeviceCallback(t *testing.T) {
352353 code : "somecode" ,
353354 error : "<script>console.log(window);</script>" ,
354355 },
355- expectedResponseCode : http .StatusBadRequest ,
356- expectedServerResponse : "<script>console.log(window);</script>: \n " ,
356+ expectedResponseCode : http .StatusBadRequest ,
357+ // Note: XSS data should NOT be displayed to user anymore.
358+ // Instead, a safe generic message is shown.
357359 },
358360 }
359361 for _ , tc := range tests {
@@ -413,6 +415,29 @@ func TestDeviceCallback(t *testing.T) {
413415 t .Errorf ("%s: Unexpected Response. Expected %q got %q" , tc .testName , tc .expectedServerResponse , result )
414416 }
415417 }
418+
419+ // Special check for error message safety tests
420+ if tc .testName == "Prevent cross-site scripting" || tc .testName == "Error During Authorization" {
421+ result , _ := io .ReadAll (rr .Body )
422+ responseBody := string (result )
423+
424+ // Error details should NOT be present in the response (for security)
425+ if tc .testName == "Prevent cross-site scripting" {
426+ if strings .Contains (responseBody , "<script>" ) || strings .Contains (responseBody , "console.log(window)" ) {
427+ t .Errorf ("%s: XSS script found in response, but should be blocked: %q" , tc .testName , responseBody )
428+ }
429+ }
430+ if tc .testName == "Error During Authorization" {
431+ if strings .Contains (responseBody , "Error Condition" ) {
432+ t .Errorf ("%s: Error details found in response, but should be hidden: %q" , tc .testName , responseBody )
433+ }
434+ }
435+
436+ // Safe message should be present
437+ if ! strings .Contains (responseBody , "Authorization failed. Please try again." ) {
438+ t .Errorf ("%s: Safe error message not found in response: %q" , tc .testName , responseBody )
439+ }
440+ }
416441 })
417442 }
418443}
0 commit comments