Fossil SCM
In login_redirect_to_g(), follow the fossil-goto value only when it names a page of this repository, and go to the home page otherwise. The value may come from a query or form field, so a login link could send the user to another site.
Commit
fb3970684dd6b7980d08d5071b413c3caad8129b791d9784508719fa6ba20e63
Parent
d57dbc4b5fc94f8…
1 file changed
+6
-1
+6
-1
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -122,12 +122,17 @@ | ||
| 122 | 122 | NORETURN void login_redirect_to_g(void){ |
| 123 | 123 | const char *zGoto = P("g"); |
| 124 | 124 | if( zGoto ){ |
| 125 | 125 | cgi_redirectf("%R/%s",zGoto); |
| 126 | 126 | }else if( (zGoto = P("fossil-goto"))!=0 && zGoto[0]!=0 ){ |
| 127 | + int n = g.zBaseURL ? (int)strlen(g.zBaseURL) : 0; | |
| 127 | 128 | cgi_set_cookie("fossil-goto","",0,1); |
| 128 | - cgi_redirect(zGoto); | |
| 129 | + if( n>0 && strncmp(zGoto, g.zBaseURL, n)==0 | |
| 130 | + && (zGoto[n]==0 || zGoto[n]=='/') ){ | |
| 131 | + cgi_redirect(zGoto); | |
| 132 | + } | |
| 133 | + fossil_redirect_home(); | |
| 129 | 134 | }else{ |
| 130 | 135 | fossil_redirect_home(); |
| 131 | 136 | } |
| 132 | 137 | } |
| 133 | 138 | |
| 134 | 139 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -122,12 +122,17 @@ | |
| 122 | NORETURN void login_redirect_to_g(void){ |
| 123 | const char *zGoto = P("g"); |
| 124 | if( zGoto ){ |
| 125 | cgi_redirectf("%R/%s",zGoto); |
| 126 | }else if( (zGoto = P("fossil-goto"))!=0 && zGoto[0]!=0 ){ |
| 127 | cgi_set_cookie("fossil-goto","",0,1); |
| 128 | cgi_redirect(zGoto); |
| 129 | }else{ |
| 130 | fossil_redirect_home(); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -122,12 +122,17 @@ | |
| 122 | NORETURN void login_redirect_to_g(void){ |
| 123 | const char *zGoto = P("g"); |
| 124 | if( zGoto ){ |
| 125 | cgi_redirectf("%R/%s",zGoto); |
| 126 | }else if( (zGoto = P("fossil-goto"))!=0 && zGoto[0]!=0 ){ |
| 127 | int n = g.zBaseURL ? (int)strlen(g.zBaseURL) : 0; |
| 128 | cgi_set_cookie("fossil-goto","",0,1); |
| 129 | if( n>0 && strncmp(zGoto, g.zBaseURL, n)==0 |
| 130 | && (zGoto[n]==0 || zGoto[n]=='/') ){ |
| 131 | cgi_redirect(zGoto); |
| 132 | } |
| 133 | fossil_redirect_home(); |
| 134 | }else{ |
| 135 | fossil_redirect_home(); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 |