Fossil SCM
Only record the first 16 bits of the 32-bit IP address as part of the anonymous login cookie.
Commit
86cbb69af2db4a05f600ff6a073618f0a89365e7
Parent
9d3fe01ae333adc…
1 file changed
+22
-2
+22
-2
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -78,10 +78,29 @@ | ||
| 78 | 78 | }else{ |
| 79 | 79 | fossil_redirect_home(); |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 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 | + | |
| 83 | 102 | /* |
| 84 | 103 | ** Check to see if the anonymous login is valid. If it is valid, return |
| 85 | 104 | ** the userid of the anonymous user. |
| 86 | 105 | */ |
| 87 | 106 | static int isValidAnonymousLogin( |
| @@ -168,11 +187,11 @@ | ||
| 168 | 187 | |
| 169 | 188 | zIpAddr = PD("REMOTE_ADDR","nil"); |
| 170 | 189 | zCookieName = login_cookie_name(); |
| 171 | 190 | zNow = db_text("0", "SELECT julianday('now')"); |
| 172 | 191 | 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","")); | |
| 174 | 193 | sha1sum_blob(&b, &b); |
| 175 | 194 | zCookie = sqlite3_mprintf("anon/%s/%s", zNow, blob_buffer(&b)); |
| 176 | 195 | blob_reset(&b); |
| 177 | 196 | free(zNow); |
| 178 | 197 | cgi_set_cookie(zCookieName, zCookie, 0, 6*3600); |
| @@ -358,11 +377,12 @@ | ||
| 358 | 377 | rTime = atof(&zCookie[5]); |
| 359 | 378 | for(i=5; zCookie[i] && zCookie[i]!='/'; i++){} |
| 360 | 379 | blob_init(&b, &zCookie[5], i-5); |
| 361 | 380 | if( zCookie[i]=='/' ){ i++; } |
| 362 | 381 | 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","")); | |
| 364 | 384 | sha1sum_blob(&b, &b); |
| 365 | 385 | uid = db_int(0, |
| 366 | 386 | "SELECT uid FROM user WHERE login='anonymous'" |
| 367 | 387 | " AND length(cap)>0" |
| 368 | 388 | " AND length(pw)>0" |
| 369 | 389 |
| --- 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 |