@@ -219,6 +219,44 @@ describe('prefix-based routing', () => {
219219 ) ;
220220 } ) ;
221221
222+ describe ( 'open redirect prevention' , ( ) => {
223+ it ( 'redirects to a same-origin URL when the path contains a TAB after decodeURI' , ( ) => {
224+ middleware ( createMockRequest ( '/en/\t/example.org' ) ) ;
225+ expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
226+ expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
227+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
228+ 'http://localhost:3000/example.org'
229+ ) ;
230+ } ) ;
231+
232+ it ( 'redirects to a same-origin URL when the path contains an encoded backslash' , ( ) => {
233+ middleware ( createMockRequest ( '/en/%5Cexample.org' ) ) ;
234+ expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
235+ expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
236+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
237+ 'http://localhost:3000/%5Cexample.org'
238+ ) ;
239+ } ) ;
240+
241+ it ( 'redirects to a same-origin URL when the path contains excess slashes before a segment' , ( ) => {
242+ middleware ( createMockRequest ( '/en///example.org' ) ) ;
243+ expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
244+ expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
245+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
246+ 'http://localhost:3000/example.org'
247+ ) ;
248+ } ) ;
249+
250+ it ( 'redirects to a same-origin URL when TAB is double-encoded as %2509' , ( ) => {
251+ middleware ( createMockRequest ( '/en/%2509/some-page' ) ) ;
252+ expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
253+ expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
254+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
255+ 'http://localhost:3000/%09/some-page'
256+ ) ;
257+ } ) ;
258+ } ) ;
259+
222260 it ( 'redirects requests for the default locale when prefixed at sub paths' , ( ) => {
223261 middleware ( createMockRequest ( '/en/about' ) ) ;
224262 expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
0 commit comments