@@ -59,6 +59,37 @@ func TestIsRedirectURLValidSameOrigin(t *tst.T) {
5959 redirectURL : "https://example.com:9001/path" ,
6060 want : false ,
6161 },
62+ // RFC 8252 Section 7.3: variable ports must be allowed for localhost
63+ {
64+ desc : "localhost with different port allowed (RFC 8252 Section 7.3)" ,
65+ siteURL : "http://localhost:3000" ,
66+ redirectURL : "http://localhost:8080/callback" ,
67+ want : true ,
68+ },
69+ {
70+ desc : "127.0.0.1 with different port allowed (RFC 8252 Section 7.3)" ,
71+ siteURL : "http://127.0.0.1:3000" ,
72+ redirectURL : "http://127.0.0.1:8080/callback" ,
73+ want : true ,
74+ },
75+ {
76+ desc : "localhost without port in redirect allowed (RFC 8252 Section 7.3)" ,
77+ siteURL : "http://localhost:3000" ,
78+ redirectURL : "http://localhost/callback" ,
79+ want : true ,
80+ },
81+ {
82+ desc : "localhost scheme downgrade still rejected despite RFC 8252" ,
83+ siteURL : "https://localhost:3000" ,
84+ redirectURL : "http://localhost:8080/callback" ,
85+ want : false ,
86+ },
87+ {
88+ desc : "non-localhost variable port still rejected" ,
89+ siteURL : "https://example.com:9000" ,
90+ redirectURL : "https://example.com:9001/path" ,
91+ want : false ,
92+ },
6293 }
6394
6495 for _ , c := range cases {
0 commit comments