Fossil SCM

Only record the first 16 bits of the 32-bit IP address as part of the anonymous login cookie.

drh 2009-12-29 00:11 trunk
Commit 86cbb69af2db4a05f600ff6a073618f0a89365e7
1 file changed +22 -2
+22 -2
--- src/login.c
+++ src/login.c
@@ -78,10 +78,29 @@
7878
}else{
7979
fossil_redirect_home();
8080
}
8181
}
8282
83
+/*
84
+** The IP address of the client is stored as part of the anonymous
85
+** login cookie for additional security. But some clients are behind
86
+** firewalls that shift the IP address with each HTTP request. To
87
+** allow such (broken) clients to log in, extract just a prefix of the
88
+** IP address.
89
+*/
90
+static char *ipPrefix(const char *zIP){
91
+ int i, j;
92
+ for(i=j=0; zIP[i]; i++){
93
+ if( zIP[i]=='.' ){
94
+ j++;
95
+ if( j==2 ) break;
96
+ }
97
+ }
98
+ return mprintf("%.*s", j, zIP);
99
+}
100
+
101
+
83102
/*
84103
** Check to see if the anonymous login is valid. If it is valid, return
85104
** the userid of the anonymous user.
86105
*/
87106
static int isValidAnonymousLogin(
@@ -168,11 +187,11 @@
168187
169188
zIpAddr = PD("REMOTE_ADDR","nil");
170189
zCookieName = login_cookie_name();
171190
zNow = db_text("0", "SELECT julianday('now')");
172191
blob_init(&b, zNow, -1);
173
- blob_appendf(&b, "/%s/%s", zIpAddr, db_get("captcha-secret",""));
192
+ blob_appendf(&b, "/%z/%s", ipPrefix(zIpAddr), db_get("captcha-secret",""));
174193
sha1sum_blob(&b, &b);
175194
zCookie = sqlite3_mprintf("anon/%s/%s", zNow, blob_buffer(&b));
176195
blob_reset(&b);
177196
free(zNow);
178197
cgi_set_cookie(zCookieName, zCookie, 0, 6*3600);
@@ -358,11 +377,12 @@
358377
rTime = atof(&zCookie[5]);
359378
for(i=5; zCookie[i] && zCookie[i]!='/'; i++){}
360379
blob_init(&b, &zCookie[5], i-5);
361380
if( zCookie[i]=='/' ){ i++; }
362381
blob_append(&b, "/", 1);
363
- blob_appendf(&b, "%s/%s", zRemoteAddr, db_get("captcha-secret",""));
382
+ blob_appendf(&b, "%z/%s", ipPrefix(zRemoteAddr),
383
+ db_get("captcha-secret",""));
364384
sha1sum_blob(&b, &b);
365385
uid = db_int(0,
366386
"SELECT uid FROM user WHERE login='anonymous'"
367387
" AND length(cap)>0"
368388
" AND length(pw)>0"
369389
--- src/login.c
+++ src/login.c
@@ -78,10 +78,29 @@
78 }else{
79 fossil_redirect_home();
80 }
81 }
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83 /*
84 ** Check to see if the anonymous login is valid. If it is valid, return
85 ** the userid of the anonymous user.
86 */
87 static int isValidAnonymousLogin(
@@ -168,11 +187,11 @@
168
169 zIpAddr = PD("REMOTE_ADDR","nil");
170 zCookieName = login_cookie_name();
171 zNow = db_text("0", "SELECT julianday('now')");
172 blob_init(&b, zNow, -1);
173 blob_appendf(&b, "/%s/%s", zIpAddr, db_get("captcha-secret",""));
174 sha1sum_blob(&b, &b);
175 zCookie = sqlite3_mprintf("anon/%s/%s", zNow, blob_buffer(&b));
176 blob_reset(&b);
177 free(zNow);
178 cgi_set_cookie(zCookieName, zCookie, 0, 6*3600);
@@ -358,11 +377,12 @@
358 rTime = atof(&zCookie[5]);
359 for(i=5; zCookie[i] && zCookie[i]!='/'; i++){}
360 blob_init(&b, &zCookie[5], i-5);
361 if( zCookie[i]=='/' ){ i++; }
362 blob_append(&b, "/", 1);
363 blob_appendf(&b, "%s/%s", zRemoteAddr, db_get("captcha-secret",""));
 
364 sha1sum_blob(&b, &b);
365 uid = db_int(0,
366 "SELECT uid FROM user WHERE login='anonymous'"
367 " AND length(cap)>0"
368 " AND length(pw)>0"
369
--- src/login.c
+++ src/login.c
@@ -78,10 +78,29 @@
78 }else{
79 fossil_redirect_home();
80 }
81 }
82
83 /*
84 ** The IP address of the client is stored as part of the anonymous
85 ** login cookie for additional security. But some clients are behind
86 ** firewalls that shift the IP address with each HTTP request. To
87 ** allow such (broken) clients to log in, extract just a prefix of the
88 ** IP address.
89 */
90 static char *ipPrefix(const char *zIP){
91 int i, j;
92 for(i=j=0; zIP[i]; i++){
93 if( zIP[i]=='.' ){
94 j++;
95 if( j==2 ) break;
96 }
97 }
98 return mprintf("%.*s", j, zIP);
99 }
100
101
102 /*
103 ** Check to see if the anonymous login is valid. If it is valid, return
104 ** the userid of the anonymous user.
105 */
106 static int isValidAnonymousLogin(
@@ -168,11 +187,11 @@
187
188 zIpAddr = PD("REMOTE_ADDR","nil");
189 zCookieName = login_cookie_name();
190 zNow = db_text("0", "SELECT julianday('now')");
191 blob_init(&b, zNow, -1);
192 blob_appendf(&b, "/%z/%s", ipPrefix(zIpAddr), db_get("captcha-secret",""));
193 sha1sum_blob(&b, &b);
194 zCookie = sqlite3_mprintf("anon/%s/%s", zNow, blob_buffer(&b));
195 blob_reset(&b);
196 free(zNow);
197 cgi_set_cookie(zCookieName, zCookie, 0, 6*3600);
@@ -358,11 +377,12 @@
377 rTime = atof(&zCookie[5]);
378 for(i=5; zCookie[i] && zCookie[i]!='/'; i++){}
379 blob_init(&b, &zCookie[5], i-5);
380 if( zCookie[i]=='/' ){ i++; }
381 blob_append(&b, "/", 1);
382 blob_appendf(&b, "%z/%s", ipPrefix(zRemoteAddr),
383 db_get("captcha-secret",""));
384 sha1sum_blob(&b, &b);
385 uid = db_int(0,
386 "SELECT uid FROM user WHERE login='anonymous'"
387 " AND length(cap)>0"
388 " AND length(pw)>0"
389

Keyboard Shortcuts

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