@@ -158,6 +158,39 @@ describe('createClerkRequest', () => {
158158 const req2 = new Request ( 'http://localhost:3000////path' ) ;
159159 expect ( createClerkRequest ( req2 ) . clerkUrl . toString ( ) ) . toBe ( 'http://localhost:3000////path' ) ;
160160 } ) ;
161+
162+ it ( 'handles malicious host header with script injection gracefully' , ( ) => {
163+ const req = new Request ( 'http://localhost:3000/path' , {
164+ headers : {
165+ 'x-forwarded-host' : 'z2cgvm.xfh"></script><script>alert(document.domain);</script>/' ,
166+ 'x-forwarded-proto' : 'https' ,
167+ } ,
168+ } ) ;
169+ expect ( ( ) => createClerkRequest ( req ) ) . not . toThrow ( ) ;
170+ expect ( createClerkRequest ( req ) . clerkUrl . toString ( ) ) . toBe ( 'http://localhost:3000/path' ) ;
171+ } ) ;
172+
173+ it ( 'handles malicious host header with invalid characters gracefully' , ( ) => {
174+ const req = new Request ( 'http://localhost:3000/path?foo=bar' , {
175+ headers : {
176+ 'x-forwarded-host' : '<invalid>host' ,
177+ 'x-forwarded-proto' : 'https' ,
178+ } ,
179+ } ) ;
180+ expect ( ( ) => createClerkRequest ( req ) ) . not . toThrow ( ) ;
181+ expect ( createClerkRequest ( req ) . clerkUrl . toString ( ) ) . toBe ( 'http://localhost:3000/path?foo=bar' ) ;
182+ } ) ;
183+
184+ it ( 'handles empty forwarded headers gracefully' , ( ) => {
185+ const req = new Request ( 'http://localhost:3000/path' , {
186+ headers : {
187+ 'x-forwarded-host' : '' ,
188+ 'x-forwarded-proto' : '' ,
189+ } ,
190+ } ) ;
191+ expect ( ( ) => createClerkRequest ( req ) ) . not . toThrow ( ) ;
192+ expect ( createClerkRequest ( req ) . clerkUrl . toString ( ) ) . toBe ( 'http://localhost:3000/path' ) ;
193+ } ) ;
161194 } ) ;
162195
163196 describe ( 'toJSON' , ( ) => {
0 commit comments