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.

dmestas 2026-11-21 15:11 UTC small-fixes
Commit fb3970684dd6b7980d08d5071b413c3caad8129b791d9784508719fa6ba20e63
1 file changed +6 -1
+6 -1
--- src/login.c
+++ src/login.c
@@ -122,12 +122,17 @@
122122
NORETURN void login_redirect_to_g(void){
123123
const char *zGoto = P("g");
124124
if( zGoto ){
125125
cgi_redirectf("%R/%s",zGoto);
126126
}else if( (zGoto = P("fossil-goto"))!=0 && zGoto[0]!=0 ){
127
+ int n = g.zBaseURL ? (int)strlen(g.zBaseURL) : 0;
127128
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();
129134
}else{
130135
fossil_redirect_home();
131136
}
132137
}
133138
134139
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button