@@ -11,73 +11,77 @@ describe("validateRedirectUrl", () => {
11
11
} ) ;
12
12
13
13
it ( "should allow URLs with ports" , ( ) => {
14
- expect ( ( ) => validateRedirectUrl ( "https://example.com:8080" ) ) . not . toThrow ( ) ;
14
+ expect ( ( ) =>
15
+ validateRedirectUrl ( "https://example.com:8080" ) ,
16
+ ) . not . toThrow ( ) ;
15
17
} ) ;
16
18
17
19
it ( "should allow URLs with paths" , ( ) => {
18
- expect ( ( ) => validateRedirectUrl ( "https://example.com/path/to/auth" ) ) . not . toThrow ( ) ;
20
+ expect ( ( ) =>
21
+ validateRedirectUrl ( "https://example.com/path/to/auth" ) ,
22
+ ) . not . toThrow ( ) ;
19
23
} ) ;
20
24
21
25
it ( "should allow URLs with query parameters" , ( ) => {
22
- expect ( ( ) => validateRedirectUrl ( "https://example.com?param=value" ) ) . not . toThrow ( ) ;
26
+ expect ( ( ) =>
27
+ validateRedirectUrl ( "https://example.com?param=value" ) ,
28
+ ) . not . toThrow ( ) ;
23
29
} ) ;
24
30
} ) ;
25
31
26
32
describe ( "invalid URLs - XSS vectors" , ( ) => {
27
33
it ( "should block javascript: protocol" , ( ) => {
28
34
expect ( ( ) => validateRedirectUrl ( "javascript:alert('XSS')" ) ) . toThrow (
29
- "Authorization URL must be HTTP or HTTPS"
35
+ "Authorization URL must be HTTP or HTTPS" ,
30
36
) ;
31
37
} ) ;
32
38
33
39
it ( "should block javascript: with encoded characters" , ( ) => {
34
- expect ( ( ) => validateRedirectUrl ( "javascript:alert%28%27XSS%27%29" ) ) . toThrow (
35
- "Authorization URL must be HTTP or HTTPS"
36
- ) ;
40
+ expect ( ( ) =>
41
+ validateRedirectUrl ( "javascript:alert%28%27XSS%27%29" ) ,
42
+ ) . toThrow ( "Authorization URL must be HTTP or HTTPS" ) ;
37
43
} ) ;
38
44
39
45
it ( "should block data: protocol" , ( ) => {
40
- expect ( ( ) => validateRedirectUrl ( "data:text/html,<script>alert('XSS')</script>" ) ) . toThrow (
41
- "Authorization URL must be HTTP or HTTPS"
42
- ) ;
46
+ expect ( ( ) =>
47
+ validateRedirectUrl ( "data:text/html,<script>alert('XSS')</script>" ) ,
48
+ ) . toThrow ( "Authorization URL must be HTTP or HTTPS" ) ;
43
49
} ) ;
44
50
45
51
it ( "should block vbscript: protocol" , ( ) => {
46
52
expect ( ( ) => validateRedirectUrl ( "vbscript:msgbox" ) ) . toThrow (
47
- "Authorization URL must be HTTP or HTTPS"
53
+ "Authorization URL must be HTTP or HTTPS" ,
48
54
) ;
49
55
} ) ;
50
56
51
57
it ( "should block file: protocol" , ( ) => {
52
58
expect ( ( ) => validateRedirectUrl ( "file:///etc/passwd" ) ) . toThrow (
53
- "Authorization URL must be HTTP or HTTPS"
59
+ "Authorization URL must be HTTP or HTTPS" ,
54
60
) ;
55
61
} ) ;
56
62
57
63
it ( "should block about: protocol" , ( ) => {
58
64
expect ( ( ) => validateRedirectUrl ( "about:blank" ) ) . toThrow (
59
- "Authorization URL must be HTTP or HTTPS"
65
+ "Authorization URL must be HTTP or HTTPS" ,
60
66
) ;
61
67
} ) ;
62
68
63
69
it ( "should block custom protocols" , ( ) => {
64
70
expect ( ( ) => validateRedirectUrl ( "custom://example" ) ) . toThrow (
65
- "Authorization URL must be HTTP or HTTPS"
71
+ "Authorization URL must be HTTP or HTTPS" ,
66
72
) ;
67
73
} ) ;
68
74
} ) ;
69
75
70
76
describe ( "edge cases" , ( ) => {
71
77
it ( "should handle malformed URLs" , ( ) => {
72
78
expect ( ( ) => validateRedirectUrl ( "not a url" ) ) . toThrow (
73
- "Invalid URL: not a url"
79
+ "Invalid URL: not a url" ,
74
80
) ;
75
81
} ) ;
76
82
77
83
it ( "should handle empty string" , ( ) => {
78
- expect ( ( ) => validateRedirectUrl ( "" ) ) . toThrow (
79
- "Invalid URL: "
80
- ) ;
84
+ expect ( ( ) => validateRedirectUrl ( "" ) ) . toThrow ( "Invalid URL: " ) ;
81
85
} ) ;
82
86
83
87
it ( "should handle URLs with unicode characters" , ( ) => {
@@ -91,12 +95,14 @@ describe("validateRedirectUrl", () => {
91
95
92
96
it ( "should handle protocol-relative URLs as invalid" , ( ) => {
93
97
expect ( ( ) => validateRedirectUrl ( "//example.com" ) ) . toThrow (
94
- "Invalid URL: //example.com"
98
+ "Invalid URL: //example.com" ,
95
99
) ;
96
100
} ) ;
97
101
98
102
it ( "should handle URLs with authentication" , ( ) => {
99
- expect ( ( ) => validateRedirectUrl ( "https://user:[email protected] " ) ) . not . toThrow ( ) ;
103
+ expect ( ( ) =>
104
+ validateRedirectUrl ( "https://user:[email protected] " ) ,
105
+ ) . not . toThrow ( ) ;
100
106
} ) ;
101
107
} ) ;
102
108
@@ -107,7 +113,9 @@ describe("validateRedirectUrl", () => {
107
113
} ) ;
108
114
109
115
it ( "should handle null bytes" , ( ) => {
110
- expect ( ( ) => validateRedirectUrl ( "java\x00script:alert('XSS')" ) ) . toThrow ( ) ;
116
+ expect ( ( ) =>
117
+ validateRedirectUrl ( "java\x00script:alert('XSS')" ) ,
118
+ ) . toThrow ( ) ;
111
119
} ) ;
112
120
113
121
it ( "should handle tab characters" , ( ) => {
@@ -120,8 +128,8 @@ describe("validateRedirectUrl", () => {
120
128
121
129
it ( "should handle mixed case protocols" , ( ) => {
122
130
expect ( ( ) => validateRedirectUrl ( "JaVaScRiPt:alert('XSS')" ) ) . toThrow (
123
- "Authorization URL must be HTTP or HTTPS"
131
+ "Authorization URL must be HTTP or HTTPS" ,
124
132
) ;
125
133
} ) ;
126
134
} ) ;
127
- } ) ;
135
+ } ) ;
0 commit comments