Fossil SCM

In the ssh transport and in "fossil ui HOST:REPO", refuse a repository name that holds a character special to a shell, and refuse such a character in the fossil= parameter of an ssh:// URL. The name was quoted for the local shell only, and the login shell on the remote system parsed it again. An ssh:// URL that is refused is reported as a failed sync and no longer as a fatal error.

dmestas 2026-11-14 16:37 UTC trunk
Commit e6c67c8b596813f04101c207b793d7bdd6a427e6ba5bf734f0c9d1a6b2652198
--- src/http_transport.c
+++ src/http_transport.c
@@ -74,19 +74,32 @@
7474
if( resetFlag ){
7575
transport.nSent = 0;
7676
transport.nRcvd = 0;
7777
}
7878
}
79
+
80
+/*
81
+** Whatever follows the host name on an ssh command line is joined into
82
+** one string by ssh and parsed again by the login shell on the remote
83
+** system. Quoting for the local shell does not protect an argument
84
+** from that second parse. Return true if zArg holds none of the
85
+** characters that a shell treats specially, so that the remote shell
86
+** takes it as a single word, unchanged.
87
+*/
88
+int ssh_remote_arg_is_safe(const char *zArg){
89
+ return strpbrk(zArg, " !\"#$&'()*;<>?[]^`{|}")==0;
90
+}
7991
8092
/*
8193
** Check zFossil to see if it is a reasonable "fossil" command to
8294
** run on the server. Do not allow an attacker to substitute something
83
-** like "/bin/rm".
95
+** like "/bin/rm", or to add to the command.
8496
*/
8597
static int is_safe_fossil_command(const char *zFossil){
8698
static const char *const azSafe[] = { "*/fossil", "*/fossil.exe", "*/echo" };
8799
int i;
100
+ if( !ssh_remote_arg_is_safe(zFossil) ) return 0;
88101
for(i=0; i<(int)(sizeof(azSafe)/sizeof(azSafe[0])); i++){
89102
if( sqlite3_strglob(azSafe[i], zFossil)==0 ) return 1;
90103
if( strcmp(azSafe[i]+2, zFossil)==0 ) return 1;
91104
}
92105
return 0;
@@ -138,21 +151,30 @@
138151
blob_append_escaped_arg(&zCmd, pUrlData->name, 0);
139152
}
140153
if( (pUrlData->flags & URL_SSH_EXE)!=0
141154
&& !is_safe_fossil_command(pUrlData->fossil)
142155
){
143
- fossil_fatal("the ssh:// URL is asking to run an unsafe command [%s] on "
144
- "the server.", pUrlData->fossil);
156
+ socket_set_errmsg("the ssh:// URL is asking to run an unsafe command "
157
+ "[%s] on the server.", pUrlData->fossil);
158
+ blob_reset(&zCmd);
159
+ return 1;
145160
}
146161
if( (pUrlData->flags & URL_SSH_EXE)==0
147162
&& (pUrlData->flags & URL_SSH_PATH)!=0
148163
){
149164
ssh_add_path_argument(&zCmd);
150165
}
151166
blob_append_escaped_arg(&zCmd, pUrlData->fossil, 1);
152167
blob_append(&zCmd, " test-http", 10);
153168
if( pUrlData->path && pUrlData->path[0] ){
169
+ if( !ssh_remote_arg_is_safe(pUrlData->path) ){
170
+ socket_set_errmsg("the repository path \"%s\" in the ssh:// URL "
171
+ "contains a character that is special to the shell "
172
+ "on the remote system", pUrlData->path);
173
+ blob_reset(&zCmd);
174
+ return 1;
175
+ }
154176
blob_append_escaped_arg(&zCmd, pUrlData->path, 1);
155177
}else{
156178
fossil_fatal("ssh:// URI does not specify a path to the repository");
157179
}
158180
if( g.fSshTrace || g.fHttpTrace ){
159181
--- src/http_transport.c
+++ src/http_transport.c
@@ -74,19 +74,32 @@
74 if( resetFlag ){
75 transport.nSent = 0;
76 transport.nRcvd = 0;
77 }
78 }
 
 
 
 
 
 
 
 
 
 
 
 
79
80 /*
81 ** Check zFossil to see if it is a reasonable "fossil" command to
82 ** run on the server. Do not allow an attacker to substitute something
83 ** like "/bin/rm".
84 */
85 static int is_safe_fossil_command(const char *zFossil){
86 static const char *const azSafe[] = { "*/fossil", "*/fossil.exe", "*/echo" };
87 int i;
 
88 for(i=0; i<(int)(sizeof(azSafe)/sizeof(azSafe[0])); i++){
89 if( sqlite3_strglob(azSafe[i], zFossil)==0 ) return 1;
90 if( strcmp(azSafe[i]+2, zFossil)==0 ) return 1;
91 }
92 return 0;
@@ -138,21 +151,30 @@
138 blob_append_escaped_arg(&zCmd, pUrlData->name, 0);
139 }
140 if( (pUrlData->flags & URL_SSH_EXE)!=0
141 && !is_safe_fossil_command(pUrlData->fossil)
142 ){
143 fossil_fatal("the ssh:// URL is asking to run an unsafe command [%s] on "
144 "the server.", pUrlData->fossil);
 
 
145 }
146 if( (pUrlData->flags & URL_SSH_EXE)==0
147 && (pUrlData->flags & URL_SSH_PATH)!=0
148 ){
149 ssh_add_path_argument(&zCmd);
150 }
151 blob_append_escaped_arg(&zCmd, pUrlData->fossil, 1);
152 blob_append(&zCmd, " test-http", 10);
153 if( pUrlData->path && pUrlData->path[0] ){
 
 
 
 
 
 
 
154 blob_append_escaped_arg(&zCmd, pUrlData->path, 1);
155 }else{
156 fossil_fatal("ssh:// URI does not specify a path to the repository");
157 }
158 if( g.fSshTrace || g.fHttpTrace ){
159
--- src/http_transport.c
+++ src/http_transport.c
@@ -74,19 +74,32 @@
74 if( resetFlag ){
75 transport.nSent = 0;
76 transport.nRcvd = 0;
77 }
78 }
79
80 /*
81 ** Whatever follows the host name on an ssh command line is joined into
82 ** one string by ssh and parsed again by the login shell on the remote
83 ** system. Quoting for the local shell does not protect an argument
84 ** from that second parse. Return true if zArg holds none of the
85 ** characters that a shell treats specially, so that the remote shell
86 ** takes it as a single word, unchanged.
87 */
88 int ssh_remote_arg_is_safe(const char *zArg){
89 return strpbrk(zArg, " !\"#$&'()*;<>?[]^`{|}")==0;
90 }
91
92 /*
93 ** Check zFossil to see if it is a reasonable "fossil" command to
94 ** run on the server. Do not allow an attacker to substitute something
95 ** like "/bin/rm", or to add to the command.
96 */
97 static int is_safe_fossil_command(const char *zFossil){
98 static const char *const azSafe[] = { "*/fossil", "*/fossil.exe", "*/echo" };
99 int i;
100 if( !ssh_remote_arg_is_safe(zFossil) ) return 0;
101 for(i=0; i<(int)(sizeof(azSafe)/sizeof(azSafe[0])); i++){
102 if( sqlite3_strglob(azSafe[i], zFossil)==0 ) return 1;
103 if( strcmp(azSafe[i]+2, zFossil)==0 ) return 1;
104 }
105 return 0;
@@ -138,21 +151,30 @@
151 blob_append_escaped_arg(&zCmd, pUrlData->name, 0);
152 }
153 if( (pUrlData->flags & URL_SSH_EXE)!=0
154 && !is_safe_fossil_command(pUrlData->fossil)
155 ){
156 socket_set_errmsg("the ssh:// URL is asking to run an unsafe command "
157 "[%s] on the server.", pUrlData->fossil);
158 blob_reset(&zCmd);
159 return 1;
160 }
161 if( (pUrlData->flags & URL_SSH_EXE)==0
162 && (pUrlData->flags & URL_SSH_PATH)!=0
163 ){
164 ssh_add_path_argument(&zCmd);
165 }
166 blob_append_escaped_arg(&zCmd, pUrlData->fossil, 1);
167 blob_append(&zCmd, " test-http", 10);
168 if( pUrlData->path && pUrlData->path[0] ){
169 if( !ssh_remote_arg_is_safe(pUrlData->path) ){
170 socket_set_errmsg("the repository path \"%s\" in the ssh:// URL "
171 "contains a character that is special to the shell "
172 "on the remote system", pUrlData->path);
173 blob_reset(&zCmd);
174 return 1;
175 }
176 blob_append_escaped_arg(&zCmd, pUrlData->path, 1);
177 }else{
178 fossil_fatal("ssh:// URI does not specify a path to the repository");
179 }
180 if( g.fSshTrace || g.fHttpTrace ){
181
+4
--- src/main.c
+++ src/main.c
@@ -3563,10 +3563,14 @@
35633563
int bRunning = 0; /* True when fossil starts up on the remote */
35643564
int isRetry; /* True if on the second attempt */
35653565
const char *zUrl = g.argv[2];
35663566
char zLine[1000];
35673567
3568
+ if( !ssh_remote_arg_is_safe(zUrl) ){
3569
+ fossil_fatal("the repository name \"%s\" contains a character that "
3570
+ "is special to the shell on the remote system", zUrl);
3571
+ }
35683572
blob_init(&ssh, 0, 0);
35693573
for(isRetry=0; isRetry<2 && !bRunning; isRetry++){
35703574
blob_reset(&ssh);
35713575
transport_ssh_command(&ssh);
35723576
blob_appendf(&ssh,
35733577
--- src/main.c
+++ src/main.c
@@ -3563,10 +3563,14 @@
3563 int bRunning = 0; /* True when fossil starts up on the remote */
3564 int isRetry; /* True if on the second attempt */
3565 const char *zUrl = g.argv[2];
3566 char zLine[1000];
3567
 
 
 
 
3568 blob_init(&ssh, 0, 0);
3569 for(isRetry=0; isRetry<2 && !bRunning; isRetry++){
3570 blob_reset(&ssh);
3571 transport_ssh_command(&ssh);
3572 blob_appendf(&ssh,
3573
--- src/main.c
+++ src/main.c
@@ -3563,10 +3563,14 @@
3563 int bRunning = 0; /* True when fossil starts up on the remote */
3564 int isRetry; /* True if on the second attempt */
3565 const char *zUrl = g.argv[2];
3566 char zLine[1000];
3567
3568 if( !ssh_remote_arg_is_safe(zUrl) ){
3569 fossil_fatal("the repository name \"%s\" contains a character that "
3570 "is special to the shell on the remote system", zUrl);
3571 }
3572 blob_init(&ssh, 0, 0);
3573 for(isRetry=0; isRetry<2 && !bRunning; isRetry++){
3574 blob_reset(&ssh);
3575 transport_ssh_command(&ssh);
3576 blob_appendf(&ssh,
3577

Keyboard Shortcuts

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