Fossil SCM

More intensive use of the Synchronizer Token Pattern for CSRF defense.

drh 2023-09-18 15:10 csrf-defense-enhancement
Commit 0a66be2b7545262a62ec8f45ce82a6ff32750ab8d4038d0e285f1f4684cfbd10
+7 -6
--- src/alerts.c
+++ src/alerts.c
@@ -1545,11 +1545,11 @@
15451545
}
15461546
style_set_current_feature("alerts");
15471547
alert_submenu_common();
15481548
needCaptcha = !login_is_individual();
15491549
if( P("submit")
1550
- && cgi_csrf_safe(1)
1550
+ && cgi_csrf_safe(2)
15511551
&& subscribe_error_check(&eErr,&zErr,needCaptcha)
15521552
){
15531553
/* A validated request for a new subscription has been received. */
15541554
char ssub[20];
15551555
const char *zEAddr = P("e");
@@ -1856,11 +1856,11 @@
18561856
db_commit_transaction();
18571857
cgi_redirect("subscribe");
18581858
/*NOTREACHED*/
18591859
}
18601860
alert_submenu_common();
1861
- if( P("submit")!=0 && cgi_csrf_safe(1) ){
1861
+ if( P("submit")!=0 && cgi_csrf_safe(2) ){
18621862
char newSsub[10];
18631863
int nsub = 0;
18641864
Blob update;
18651865
18661866
sdonotcall = PB("sdonotcall");
@@ -1918,11 +1918,11 @@
19181918
"UPDATE subscriber SET lastContact=now()/86400"
19191919
" WHERE subscriberId=%d", sid
19201920
);
19211921
db_protect_pop();
19221922
}
1923
- if( P("delete")!=0 && cgi_csrf_safe(1) ){
1923
+ if( P("delete")!=0 && cgi_csrf_safe(2) ){
19241924
if( !PB("dodelete") ){
19251925
eErr = 9;
19261926
zErr = mprintf("Select this checkbox and press \"Unsubscribe\" again to"
19271927
" unsubscribe");
19281928
}else{
@@ -2269,11 +2269,11 @@
22692269
22702270
style_set_current_feature("alerts");
22712271
22722272
zEAddr = PD("e","");
22732273
dx = atoi(PD("dx","0"));
2274
- bSubmit = P("submit")!=0 && P("e")!=0 && cgi_csrf_safe(1);
2274
+ bSubmit = P("submit")!=0 && P("e")!=0 && cgi_csrf_safe(2);
22752275
if( bSubmit ){
22762276
if( !captcha_is_correct(1) ){
22772277
eErr = 2;
22782278
zErr = mprintf("enter the security code shown below");
22792279
bSubmit = 0;
@@ -3300,11 +3300,11 @@
33003300
}
33013301
if( P("submit")!=0
33023302
&& P("subject")!=0
33033303
&& P("msg")!=0
33043304
&& P("from")!=0
3305
- && cgi_csrf_safe(1)
3305
+ && cgi_csrf_safe(2)
33063306
&& captcha_is_correct(0)
33073307
){
33083308
Blob hdr, body;
33093309
AlertSender *pSender = alert_sender_new(0,0);
33103310
blob_init(&hdr, 0, 0);
@@ -3477,11 +3477,11 @@
34773477
/* Visit the /announce/test1 page to see the CGI variables */
34783478
zAction = "announce/test1";
34793479
@ <p style='border: 1px solid black; padding: 1ex;'>
34803480
cgi_print_all(0, 0, 0);
34813481
@ </p>
3482
- }else if( P("submit")!=0 && cgi_csrf_safe(1) ){
3482
+ }else if( P("submit")!=0 && cgi_csrf_safe(2) ){
34833483
char *zErr = alert_send_announcement();
34843484
style_header("Announcement Sent");
34853485
if( zErr ){
34863486
@ <h1>Internal Error</h1>
34873487
@ <p>The following error was reported by the system:
@@ -3502,10 +3502,11 @@
35023502
return;
35033503
}
35043504
35053505
style_header("Send Announcement");
35063506
@ <form method="POST" action="%R/%s(zAction)">
3507
+ login_insert_csrf_secret();
35073508
@ <table class="subscribe">
35083509
if( g.perm.Admin ){
35093510
int aa = PB("aa");
35103511
int all = PB("all");
35113512
int aMod = PB("mods");
35123513
--- src/alerts.c
+++ src/alerts.c
@@ -1545,11 +1545,11 @@
1545 }
1546 style_set_current_feature("alerts");
1547 alert_submenu_common();
1548 needCaptcha = !login_is_individual();
1549 if( P("submit")
1550 && cgi_csrf_safe(1)
1551 && subscribe_error_check(&eErr,&zErr,needCaptcha)
1552 ){
1553 /* A validated request for a new subscription has been received. */
1554 char ssub[20];
1555 const char *zEAddr = P("e");
@@ -1856,11 +1856,11 @@
1856 db_commit_transaction();
1857 cgi_redirect("subscribe");
1858 /*NOTREACHED*/
1859 }
1860 alert_submenu_common();
1861 if( P("submit")!=0 && cgi_csrf_safe(1) ){
1862 char newSsub[10];
1863 int nsub = 0;
1864 Blob update;
1865
1866 sdonotcall = PB("sdonotcall");
@@ -1918,11 +1918,11 @@
1918 "UPDATE subscriber SET lastContact=now()/86400"
1919 " WHERE subscriberId=%d", sid
1920 );
1921 db_protect_pop();
1922 }
1923 if( P("delete")!=0 && cgi_csrf_safe(1) ){
1924 if( !PB("dodelete") ){
1925 eErr = 9;
1926 zErr = mprintf("Select this checkbox and press \"Unsubscribe\" again to"
1927 " unsubscribe");
1928 }else{
@@ -2269,11 +2269,11 @@
2269
2270 style_set_current_feature("alerts");
2271
2272 zEAddr = PD("e","");
2273 dx = atoi(PD("dx","0"));
2274 bSubmit = P("submit")!=0 && P("e")!=0 && cgi_csrf_safe(1);
2275 if( bSubmit ){
2276 if( !captcha_is_correct(1) ){
2277 eErr = 2;
2278 zErr = mprintf("enter the security code shown below");
2279 bSubmit = 0;
@@ -3300,11 +3300,11 @@
3300 }
3301 if( P("submit")!=0
3302 && P("subject")!=0
3303 && P("msg")!=0
3304 && P("from")!=0
3305 && cgi_csrf_safe(1)
3306 && captcha_is_correct(0)
3307 ){
3308 Blob hdr, body;
3309 AlertSender *pSender = alert_sender_new(0,0);
3310 blob_init(&hdr, 0, 0);
@@ -3477,11 +3477,11 @@
3477 /* Visit the /announce/test1 page to see the CGI variables */
3478 zAction = "announce/test1";
3479 @ <p style='border: 1px solid black; padding: 1ex;'>
3480 cgi_print_all(0, 0, 0);
3481 @ </p>
3482 }else if( P("submit")!=0 && cgi_csrf_safe(1) ){
3483 char *zErr = alert_send_announcement();
3484 style_header("Announcement Sent");
3485 if( zErr ){
3486 @ <h1>Internal Error</h1>
3487 @ <p>The following error was reported by the system:
@@ -3502,10 +3502,11 @@
3502 return;
3503 }
3504
3505 style_header("Send Announcement");
3506 @ <form method="POST" action="%R/%s(zAction)">
 
3507 @ <table class="subscribe">
3508 if( g.perm.Admin ){
3509 int aa = PB("aa");
3510 int all = PB("all");
3511 int aMod = PB("mods");
3512
--- src/alerts.c
+++ src/alerts.c
@@ -1545,11 +1545,11 @@
1545 }
1546 style_set_current_feature("alerts");
1547 alert_submenu_common();
1548 needCaptcha = !login_is_individual();
1549 if( P("submit")
1550 && cgi_csrf_safe(2)
1551 && subscribe_error_check(&eErr,&zErr,needCaptcha)
1552 ){
1553 /* A validated request for a new subscription has been received. */
1554 char ssub[20];
1555 const char *zEAddr = P("e");
@@ -1856,11 +1856,11 @@
1856 db_commit_transaction();
1857 cgi_redirect("subscribe");
1858 /*NOTREACHED*/
1859 }
1860 alert_submenu_common();
1861 if( P("submit")!=0 && cgi_csrf_safe(2) ){
1862 char newSsub[10];
1863 int nsub = 0;
1864 Blob update;
1865
1866 sdonotcall = PB("sdonotcall");
@@ -1918,11 +1918,11 @@
1918 "UPDATE subscriber SET lastContact=now()/86400"
1919 " WHERE subscriberId=%d", sid
1920 );
1921 db_protect_pop();
1922 }
1923 if( P("delete")!=0 && cgi_csrf_safe(2) ){
1924 if( !PB("dodelete") ){
1925 eErr = 9;
1926 zErr = mprintf("Select this checkbox and press \"Unsubscribe\" again to"
1927 " unsubscribe");
1928 }else{
@@ -2269,11 +2269,11 @@
2269
2270 style_set_current_feature("alerts");
2271
2272 zEAddr = PD("e","");
2273 dx = atoi(PD("dx","0"));
2274 bSubmit = P("submit")!=0 && P("e")!=0 && cgi_csrf_safe(2);
2275 if( bSubmit ){
2276 if( !captcha_is_correct(1) ){
2277 eErr = 2;
2278 zErr = mprintf("enter the security code shown below");
2279 bSubmit = 0;
@@ -3300,11 +3300,11 @@
3300 }
3301 if( P("submit")!=0
3302 && P("subject")!=0
3303 && P("msg")!=0
3304 && P("from")!=0
3305 && cgi_csrf_safe(2)
3306 && captcha_is_correct(0)
3307 ){
3308 Blob hdr, body;
3309 AlertSender *pSender = alert_sender_new(0,0);
3310 blob_init(&hdr, 0, 0);
@@ -3477,11 +3477,11 @@
3477 /* Visit the /announce/test1 page to see the CGI variables */
3478 zAction = "announce/test1";
3479 @ <p style='border: 1px solid black; padding: 1ex;'>
3480 cgi_print_all(0, 0, 0);
3481 @ </p>
3482 }else if( P("submit")!=0 && cgi_csrf_safe(2) ){
3483 char *zErr = alert_send_announcement();
3484 style_header("Announcement Sent");
3485 if( zErr ){
3486 @ <h1>Internal Error</h1>
3487 @ <p>The following error was reported by the system:
@@ -3502,10 +3502,11 @@
3502 return;
3503 }
3504
3505 style_header("Send Announcement");
3506 @ <form method="POST" action="%R/%s(zAction)">
3507 login_insert_csrf_secret();
3508 @ <table class="subscribe">
3509 if( g.perm.Admin ){
3510 int aa = PB("aa");
3511 int all = PB("all");
3512 int aMod = PB("mods");
3513
+6 -2
--- src/forum.c
+++ src/forum.c
@@ -1539,11 +1539,11 @@
15391539
login_check_credentials();
15401540
if( !g.perm.WrForum ){
15411541
login_needed(g.anon.WrForum);
15421542
return;
15431543
}
1544
- if( P("submit") && cgi_csrf_safe(1) ){
1544
+ if( P("submit") && cgi_csrf_safe(2) ){
15451545
if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent,
15461546
forum_post_flags()) ) return;
15471547
}
15481548
if( P("preview") && !whitespace_only(zContent) ){
15491549
@ <h1>Preview:</h1>
@@ -1560,10 +1560,11 @@
15601560
@ <input type="submit" name="submit" value="Submit">
15611561
}else{
15621562
@ <input type="submit" name="submit" value="Submit" disabled>
15631563
}
15641564
forum_render_debug_options();
1565
+ login_insert_csrf_secret();
15651566
@ </form>
15661567
forum_emit_js();
15671568
style_finish_page();
15681569
}
15691570
@@ -1611,11 +1612,11 @@
16111612
return;
16121613
}
16131614
bPreview = P("preview")!=0;
16141615
bReply = P("reply")!=0;
16151616
iClosed = forum_rid_is_closed(fpid, 1);
1616
- isCsrfSafe = cgi_csrf_safe(1);
1617
+ isCsrfSafe = cgi_csrf_safe(2);
16171618
bPrivate = content_is_private(fpid);
16181619
bSameUser = login_is_individual()
16191620
&& fossil_strcmp(pPost->zUser, g.zLogin)==0;
16201621
if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){
16211622
if( g.perm.ModForum && P("approve") ){
@@ -1679,10 +1680,11 @@
16791680
forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki,
16801681
"forumEdit", 1);
16811682
@ <h1>Change Into:</h1>
16821683
forum_render(zTitle, zMimetype, zContent,"forumEdit", 1);
16831684
@ <form action="%R/forume2" method="POST">
1685
+ login_insert_csrf_secret();
16841686
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
16851687
@ <input type="hidden" name="nullout" value="1">
16861688
@ <input type="hidden" name="mimetype" value="%h(zMimetype)">
16871689
@ <input type="hidden" name="content" value="%h(zContent)">
16881690
if( zTitle ){
@@ -1706,10 +1708,11 @@
17061708
@ <h2>Preview of Edited Post:</h2>
17071709
forum_render(zTitle, zMimetype, zContent,"forumEdit", 1);
17081710
}
17091711
@ <h2>Revised Message:</h2>
17101712
@ <form action="%R/forume2" method="POST">
1713
+ login_insert_csrf_secret();
17111714
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
17121715
@ <input type="hidden" name="edit" value="1">
17131716
forum_from_line();
17141717
forum_post_widget(zTitle, zMimetype, zContent);
17151718
}else{
@@ -1750,10 +1753,11 @@
17501753
if( !iClosed || g.perm.Admin ) {
17511754
@ <input type="submit" name="submit" value="Submit">
17521755
}
17531756
}
17541757
forum_render_debug_options();
1758
+ login_insert_csrf_secret();
17551759
@ </form>
17561760
forum_emit_js();
17571761
style_finish_page();
17581762
}
17591763
17601764
--- src/forum.c
+++ src/forum.c
@@ -1539,11 +1539,11 @@
1539 login_check_credentials();
1540 if( !g.perm.WrForum ){
1541 login_needed(g.anon.WrForum);
1542 return;
1543 }
1544 if( P("submit") && cgi_csrf_safe(1) ){
1545 if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent,
1546 forum_post_flags()) ) return;
1547 }
1548 if( P("preview") && !whitespace_only(zContent) ){
1549 @ <h1>Preview:</h1>
@@ -1560,10 +1560,11 @@
1560 @ <input type="submit" name="submit" value="Submit">
1561 }else{
1562 @ <input type="submit" name="submit" value="Submit" disabled>
1563 }
1564 forum_render_debug_options();
 
1565 @ </form>
1566 forum_emit_js();
1567 style_finish_page();
1568 }
1569
@@ -1611,11 +1612,11 @@
1611 return;
1612 }
1613 bPreview = P("preview")!=0;
1614 bReply = P("reply")!=0;
1615 iClosed = forum_rid_is_closed(fpid, 1);
1616 isCsrfSafe = cgi_csrf_safe(1);
1617 bPrivate = content_is_private(fpid);
1618 bSameUser = login_is_individual()
1619 && fossil_strcmp(pPost->zUser, g.zLogin)==0;
1620 if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){
1621 if( g.perm.ModForum && P("approve") ){
@@ -1679,10 +1680,11 @@
1679 forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki,
1680 "forumEdit", 1);
1681 @ <h1>Change Into:</h1>
1682 forum_render(zTitle, zMimetype, zContent,"forumEdit", 1);
1683 @ <form action="%R/forume2" method="POST">
 
1684 @ <input type="hidden" name="fpid" value="%h(P("fpid"))">
1685 @ <input type="hidden" name="nullout" value="1">
1686 @ <input type="hidden" name="mimetype" value="%h(zMimetype)">
1687 @ <input type="hidden" name="content" value="%h(zContent)">
1688 if( zTitle ){
@@ -1706,10 +1708,11 @@
1706 @ <h2>Preview of Edited Post:</h2>
1707 forum_render(zTitle, zMimetype, zContent,"forumEdit", 1);
1708 }
1709 @ <h2>Revised Message:</h2>
1710 @ <form action="%R/forume2" method="POST">
 
1711 @ <input type="hidden" name="fpid" value="%h(P("fpid"))">
1712 @ <input type="hidden" name="edit" value="1">
1713 forum_from_line();
1714 forum_post_widget(zTitle, zMimetype, zContent);
1715 }else{
@@ -1750,10 +1753,11 @@
1750 if( !iClosed || g.perm.Admin ) {
1751 @ <input type="submit" name="submit" value="Submit">
1752 }
1753 }
1754 forum_render_debug_options();
 
1755 @ </form>
1756 forum_emit_js();
1757 style_finish_page();
1758 }
1759
1760
--- src/forum.c
+++ src/forum.c
@@ -1539,11 +1539,11 @@
1539 login_check_credentials();
1540 if( !g.perm.WrForum ){
1541 login_needed(g.anon.WrForum);
1542 return;
1543 }
1544 if( P("submit") && cgi_csrf_safe(2) ){
1545 if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent,
1546 forum_post_flags()) ) return;
1547 }
1548 if( P("preview") && !whitespace_only(zContent) ){
1549 @ <h1>Preview:</h1>
@@ -1560,10 +1560,11 @@
1560 @ <input type="submit" name="submit" value="Submit">
1561 }else{
1562 @ <input type="submit" name="submit" value="Submit" disabled>
1563 }
1564 forum_render_debug_options();
1565 login_insert_csrf_secret();
1566 @ </form>
1567 forum_emit_js();
1568 style_finish_page();
1569 }
1570
@@ -1611,11 +1612,11 @@
1612 return;
1613 }
1614 bPreview = P("preview")!=0;
1615 bReply = P("reply")!=0;
1616 iClosed = forum_rid_is_closed(fpid, 1);
1617 isCsrfSafe = cgi_csrf_safe(2);
1618 bPrivate = content_is_private(fpid);
1619 bSameUser = login_is_individual()
1620 && fossil_strcmp(pPost->zUser, g.zLogin)==0;
1621 if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){
1622 if( g.perm.ModForum && P("approve") ){
@@ -1679,10 +1680,11 @@
1680 forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki,
1681 "forumEdit", 1);
1682 @ <h1>Change Into:</h1>
1683 forum_render(zTitle, zMimetype, zContent,"forumEdit", 1);
1684 @ <form action="%R/forume2" method="POST">
1685 login_insert_csrf_secret();
1686 @ <input type="hidden" name="fpid" value="%h(P("fpid"))">
1687 @ <input type="hidden" name="nullout" value="1">
1688 @ <input type="hidden" name="mimetype" value="%h(zMimetype)">
1689 @ <input type="hidden" name="content" value="%h(zContent)">
1690 if( zTitle ){
@@ -1706,10 +1708,11 @@
1708 @ <h2>Preview of Edited Post:</h2>
1709 forum_render(zTitle, zMimetype, zContent,"forumEdit", 1);
1710 }
1711 @ <h2>Revised Message:</h2>
1712 @ <form action="%R/forume2" method="POST">
1713 login_insert_csrf_secret();
1714 @ <input type="hidden" name="fpid" value="%h(P("fpid"))">
1715 @ <input type="hidden" name="edit" value="1">
1716 forum_from_line();
1717 forum_post_widget(zTitle, zMimetype, zContent);
1718 }else{
@@ -1750,10 +1753,11 @@
1753 if( !iClosed || g.perm.Admin ) {
1754 @ <input type="submit" name="submit" value="Submit">
1755 }
1756 }
1757 forum_render_debug_options();
1758 login_insert_csrf_secret();
1759 @ </form>
1760 forum_emit_js();
1761 style_finish_page();
1762 }
1763
1764
+1 -1
--- src/interwiki.c
+++ src/interwiki.c
@@ -314,11 +314,11 @@
314314
login_check_credentials();
315315
if( !g.perm.Read && !g.perm.RdWiki && ~g.perm.RdTkt ){
316316
login_needed(0);
317317
return;
318318
}
319
- if( g.perm.Setup && P("submit")!=0 && cgi_csrf_safe(1) ){
319
+ if( g.perm.Setup && P("submit")!=0 && cgi_csrf_safe(2) ){
320320
zTag = PT("tag");
321321
zBase = PT("base");
322322
zHash = PT("hash");
323323
zWiki = PT("wiki");
324324
if( zTag==0 || zTag[0]==0 || !interwiki_valid_name(zTag) ){
325325
--- src/interwiki.c
+++ src/interwiki.c
@@ -314,11 +314,11 @@
314 login_check_credentials();
315 if( !g.perm.Read && !g.perm.RdWiki && ~g.perm.RdTkt ){
316 login_needed(0);
317 return;
318 }
319 if( g.perm.Setup && P("submit")!=0 && cgi_csrf_safe(1) ){
320 zTag = PT("tag");
321 zBase = PT("base");
322 zHash = PT("hash");
323 zWiki = PT("wiki");
324 if( zTag==0 || zTag[0]==0 || !interwiki_valid_name(zTag) ){
325
--- src/interwiki.c
+++ src/interwiki.c
@@ -314,11 +314,11 @@
314 login_check_credentials();
315 if( !g.perm.Read && !g.perm.RdWiki && ~g.perm.RdTkt ){
316 login_needed(0);
317 return;
318 }
319 if( g.perm.Setup && P("submit")!=0 && cgi_csrf_safe(2) ){
320 zTag = PT("tag");
321 zBase = PT("base");
322 zHash = PT("hash");
323 zWiki = PT("wiki");
324 if( zTag==0 || zTag[0]==0 || !interwiki_valid_name(zTag) ){
325
+2 -2
--- src/login.c
+++ src/login.c
@@ -1982,11 +1982,11 @@
19821982
zConfirm = PDT("cp","");
19831983
zEAddr = PDT("ea","");
19841984
zDName = PDT("dn","");
19851985
19861986
/* Verify user imputs */
1987
- if( P("new")==0 || !cgi_csrf_safe(1) ){
1987
+ if( P("new")==0 || !cgi_csrf_safe(2) ){
19881988
/* This is not a valid form submission. Fall through into
19891989
** the form display */
19901990
}else if( (captchaIsCorrect = captcha_is_correct(1))==0 ){
19911991
iErrLine = 6;
19921992
zErr = "Incorrect CAPTCHA";
@@ -2260,11 +2260,11 @@
22602260
return;
22612261
}
22622262
zEAddr = PDT("ea","");
22632263
22642264
/* Verify user imputs */
2265
- if( !cgi_csrf_safe(1) || P("reqpwreset")==0 ){
2265
+ if( !cgi_csrf_safe(2) || P("reqpwreset")==0 ){
22662266
/* This is the initial display of the form. No processing or error
22672267
** checking is to be done. Fall through into the form display
22682268
*/
22692269
}else if( (captchaIsCorrect = captcha_is_correct(1))==0 ){
22702270
iErrLine = 2;
22712271
--- src/login.c
+++ src/login.c
@@ -1982,11 +1982,11 @@
1982 zConfirm = PDT("cp","");
1983 zEAddr = PDT("ea","");
1984 zDName = PDT("dn","");
1985
1986 /* Verify user imputs */
1987 if( P("new")==0 || !cgi_csrf_safe(1) ){
1988 /* This is not a valid form submission. Fall through into
1989 ** the form display */
1990 }else if( (captchaIsCorrect = captcha_is_correct(1))==0 ){
1991 iErrLine = 6;
1992 zErr = "Incorrect CAPTCHA";
@@ -2260,11 +2260,11 @@
2260 return;
2261 }
2262 zEAddr = PDT("ea","");
2263
2264 /* Verify user imputs */
2265 if( !cgi_csrf_safe(1) || P("reqpwreset")==0 ){
2266 /* This is the initial display of the form. No processing or error
2267 ** checking is to be done. Fall through into the form display
2268 */
2269 }else if( (captchaIsCorrect = captcha_is_correct(1))==0 ){
2270 iErrLine = 2;
2271
--- src/login.c
+++ src/login.c
@@ -1982,11 +1982,11 @@
1982 zConfirm = PDT("cp","");
1983 zEAddr = PDT("ea","");
1984 zDName = PDT("dn","");
1985
1986 /* Verify user imputs */
1987 if( P("new")==0 || !cgi_csrf_safe(2) ){
1988 /* This is not a valid form submission. Fall through into
1989 ** the form display */
1990 }else if( (captchaIsCorrect = captcha_is_correct(1))==0 ){
1991 iErrLine = 6;
1992 zErr = "Incorrect CAPTCHA";
@@ -2260,11 +2260,11 @@
2260 return;
2261 }
2262 zEAddr = PDT("ea","");
2263
2264 /* Verify user imputs */
2265 if( !cgi_csrf_safe(2) || P("reqpwreset")==0 ){
2266 /* This is the initial display of the form. No processing or error
2267 ** checking is to be done. Fall through into the form display
2268 */
2269 }else if( (captchaIsCorrect = captcha_is_correct(1))==0 ){
2270 iErrLine = 2;
2271
--- src/security_audit.c
+++ src/security_audit.c
@@ -795,11 +795,11 @@
795795
@ command.
796796
@ </ol>
797797
style_finish_page();
798798
return;
799799
}
800
- if( P("truncate1") && cgi_csrf_safe(1) ){
800
+ if( P("truncate1") && cgi_csrf_safe(2) ){
801801
fclose(fopen(g.zErrlog,"w"));
802802
}
803803
if( P("download") ){
804804
Blob log;
805805
blob_read_from_file(&log, g.zErrlog, ExtFILE);
@@ -808,10 +808,11 @@
808808
return;
809809
}
810810
szFile = file_size(g.zErrlog, ExtFILE);
811811
if( P("truncate") ){
812812
@ <form action="%R/errorlog" method="POST">
813
+ login_insert_csrf_secret();
813814
@ <p>Confirm that you want to truncate the %,lld(szFile)-byte error log:
814815
@ <input type="submit" name="truncate1" value="Confirm">
815816
@ <input type="submit" name="cancel" value="Cancel">
816817
@ </form>
817818
style_finish_page();
818819
--- src/security_audit.c
+++ src/security_audit.c
@@ -795,11 +795,11 @@
795 @ command.
796 @ </ol>
797 style_finish_page();
798 return;
799 }
800 if( P("truncate1") && cgi_csrf_safe(1) ){
801 fclose(fopen(g.zErrlog,"w"));
802 }
803 if( P("download") ){
804 Blob log;
805 blob_read_from_file(&log, g.zErrlog, ExtFILE);
@@ -808,10 +808,11 @@
808 return;
809 }
810 szFile = file_size(g.zErrlog, ExtFILE);
811 if( P("truncate") ){
812 @ <form action="%R/errorlog" method="POST">
 
813 @ <p>Confirm that you want to truncate the %,lld(szFile)-byte error log:
814 @ <input type="submit" name="truncate1" value="Confirm">
815 @ <input type="submit" name="cancel" value="Cancel">
816 @ </form>
817 style_finish_page();
818
--- src/security_audit.c
+++ src/security_audit.c
@@ -795,11 +795,11 @@
795 @ command.
796 @ </ol>
797 style_finish_page();
798 return;
799 }
800 if( P("truncate1") && cgi_csrf_safe(2) ){
801 fclose(fopen(g.zErrlog,"w"));
802 }
803 if( P("download") ){
804 Blob log;
805 blob_read_from_file(&log, g.zErrlog, ExtFILE);
@@ -808,10 +808,11 @@
808 return;
809 }
810 szFile = file_size(g.zErrlog, ExtFILE);
811 if( P("truncate") ){
812 @ <form action="%R/errorlog" method="POST">
813 login_insert_csrf_secret();
814 @ <p>Confirm that you want to truncate the %,lld(szFile)-byte error log:
815 @ <input type="submit" name="truncate1" value="Confirm">
816 @ <input type="submit" name="cancel" value="Cancel">
817 @ </form>
818 style_finish_page();
819
+4 -4
--- src/setup.c
+++ src/setup.c
@@ -1454,11 +1454,11 @@
14541454
if( !g.perm.Admin ){
14551455
login_needed(0);
14561456
return;
14571457
}
14581458
db_begin_transaction();
1459
- if( P("clear")!=0 && cgi_csrf_safe(1) ){
1459
+ if( P("clear")!=0 && cgi_csrf_safe(2) ){
14601460
db_unprotect(PROTECT_CONFIG);
14611461
db_multi_exec("DELETE FROM config WHERE name GLOB 'adunit*'");
14621462
db_protect_pop();
14631463
cgi_replace_parameter("adunit","");
14641464
cgi_replace_parameter("adright","");
@@ -1556,11 +1556,11 @@
15561556
if( !g.perm.Admin ){
15571557
login_needed(0);
15581558
return;
15591559
}
15601560
db_begin_transaction();
1561
- if( !cgi_csrf_safe(1) ){
1561
+ if( !cgi_csrf_safe(2) ){
15621562
/* Allow no state changes if not safe from CSRF */
15631563
}else if( P("setlogo")!=0 && zLogoMime && zLogoMime[0] && szLogoImg>0 ){
15641564
Blob img;
15651565
Stmt ins;
15661566
blob_init(&img, aLogoImg, szLogoImg);
@@ -1765,11 +1765,11 @@
17651765
if( !g.perm.Setup ){
17661766
login_needed(0);
17671767
return;
17681768
}
17691769
add_content_sql_commands(g.db);
1770
- zQ = cgi_csrf_safe(1) ? P("q") : 0;
1770
+ zQ = cgi_csrf_safe(2) ? P("q") : 0;
17711771
style_set_current_feature("setup");
17721772
style_header("Raw SQL Commands");
17731773
@ <p><b>Caution:</b> There are no restrictions on the SQL that can be
17741774
@ run by this page. You can do serious and irrepairable damage to the
17751775
@ repository. Proceed with extreme caution.</p>
@@ -2122,11 +2122,11 @@
21222122
Blob *pSql,
21232123
const char *zOldName,
21242124
const char *zNewName,
21252125
const char *zValue
21262126
){
2127
- if( !cgi_csrf_safe(1) ) return;
2127
+ if( !cgi_csrf_safe(2) ) return;
21282128
if( zNewName[0]==0 || zValue[0]==0 ){
21292129
if( zOldName[0] ){
21302130
blob_append_sql(pSql,
21312131
"DELETE FROM config WHERE name='walias:%q';\n",
21322132
zOldName);
21332133
--- src/setup.c
+++ src/setup.c
@@ -1454,11 +1454,11 @@
1454 if( !g.perm.Admin ){
1455 login_needed(0);
1456 return;
1457 }
1458 db_begin_transaction();
1459 if( P("clear")!=0 && cgi_csrf_safe(1) ){
1460 db_unprotect(PROTECT_CONFIG);
1461 db_multi_exec("DELETE FROM config WHERE name GLOB 'adunit*'");
1462 db_protect_pop();
1463 cgi_replace_parameter("adunit","");
1464 cgi_replace_parameter("adright","");
@@ -1556,11 +1556,11 @@
1556 if( !g.perm.Admin ){
1557 login_needed(0);
1558 return;
1559 }
1560 db_begin_transaction();
1561 if( !cgi_csrf_safe(1) ){
1562 /* Allow no state changes if not safe from CSRF */
1563 }else if( P("setlogo")!=0 && zLogoMime && zLogoMime[0] && szLogoImg>0 ){
1564 Blob img;
1565 Stmt ins;
1566 blob_init(&img, aLogoImg, szLogoImg);
@@ -1765,11 +1765,11 @@
1765 if( !g.perm.Setup ){
1766 login_needed(0);
1767 return;
1768 }
1769 add_content_sql_commands(g.db);
1770 zQ = cgi_csrf_safe(1) ? P("q") : 0;
1771 style_set_current_feature("setup");
1772 style_header("Raw SQL Commands");
1773 @ <p><b>Caution:</b> There are no restrictions on the SQL that can be
1774 @ run by this page. You can do serious and irrepairable damage to the
1775 @ repository. Proceed with extreme caution.</p>
@@ -2122,11 +2122,11 @@
2122 Blob *pSql,
2123 const char *zOldName,
2124 const char *zNewName,
2125 const char *zValue
2126 ){
2127 if( !cgi_csrf_safe(1) ) return;
2128 if( zNewName[0]==0 || zValue[0]==0 ){
2129 if( zOldName[0] ){
2130 blob_append_sql(pSql,
2131 "DELETE FROM config WHERE name='walias:%q';\n",
2132 zOldName);
2133
--- src/setup.c
+++ src/setup.c
@@ -1454,11 +1454,11 @@
1454 if( !g.perm.Admin ){
1455 login_needed(0);
1456 return;
1457 }
1458 db_begin_transaction();
1459 if( P("clear")!=0 && cgi_csrf_safe(2) ){
1460 db_unprotect(PROTECT_CONFIG);
1461 db_multi_exec("DELETE FROM config WHERE name GLOB 'adunit*'");
1462 db_protect_pop();
1463 cgi_replace_parameter("adunit","");
1464 cgi_replace_parameter("adright","");
@@ -1556,11 +1556,11 @@
1556 if( !g.perm.Admin ){
1557 login_needed(0);
1558 return;
1559 }
1560 db_begin_transaction();
1561 if( !cgi_csrf_safe(2) ){
1562 /* Allow no state changes if not safe from CSRF */
1563 }else if( P("setlogo")!=0 && zLogoMime && zLogoMime[0] && szLogoImg>0 ){
1564 Blob img;
1565 Stmt ins;
1566 blob_init(&img, aLogoImg, szLogoImg);
@@ -1765,11 +1765,11 @@
1765 if( !g.perm.Setup ){
1766 login_needed(0);
1767 return;
1768 }
1769 add_content_sql_commands(g.db);
1770 zQ = cgi_csrf_safe(2) ? P("q") : 0;
1771 style_set_current_feature("setup");
1772 style_header("Raw SQL Commands");
1773 @ <p><b>Caution:</b> There are no restrictions on the SQL that can be
1774 @ run by this page. You can do serious and irrepairable damage to the
1775 @ repository. Proceed with extreme caution.</p>
@@ -2122,11 +2122,11 @@
2122 Blob *pSql,
2123 const char *zOldName,
2124 const char *zNewName,
2125 const char *zValue
2126 ){
2127 if( !cgi_csrf_safe(2) ) return;
2128 if( zNewName[0]==0 || zValue[0]==0 ){
2129 if( zOldName[0] ){
2130 blob_append_sql(pSql,
2131 "DELETE FROM config WHERE name='walias:%q';\n",
2132 zOldName);
2133
+1 -1
--- src/setupuser.c
+++ src/setupuser.c
@@ -342,11 +342,11 @@
342342
cgi_redirect(cgi_referer("setup_ulist"));
343343
return;
344344
}
345345
346346
/* Check for requests to delete the user */
347
- if( P("delete") && cgi_csrf_safe(1) ){
347
+ if( P("delete") && cgi_csrf_safe(2) ){
348348
int n;
349349
if( P("verifydelete") ){
350350
/* Verified delete user request */
351351
db_unprotect(PROTECT_USER);
352352
if( alert_tables_exist() ){
353353
--- src/setupuser.c
+++ src/setupuser.c
@@ -342,11 +342,11 @@
342 cgi_redirect(cgi_referer("setup_ulist"));
343 return;
344 }
345
346 /* Check for requests to delete the user */
347 if( P("delete") && cgi_csrf_safe(1) ){
348 int n;
349 if( P("verifydelete") ){
350 /* Verified delete user request */
351 db_unprotect(PROTECT_USER);
352 if( alert_tables_exist() ){
353
--- src/setupuser.c
+++ src/setupuser.c
@@ -342,11 +342,11 @@
342 cgi_redirect(cgi_referer("setup_ulist"));
343 return;
344 }
345
346 /* Check for requests to delete the user */
347 if( P("delete") && cgi_csrf_safe(2) ){
348 int n;
349 if( P("verifydelete") ){
350 /* Verified delete user request */
351 db_unprotect(PROTECT_USER);
352 if( alert_tables_exist() ){
353
+20 -1
--- src/style.c
+++ src/style.c
@@ -1460,11 +1460,30 @@
14601460
@ g.zRepositoryName = %h(g.zRepositoryName)<br>
14611461
@ load_average() = %f(load_average())<br>
14621462
#ifndef _WIN32
14631463
@ RSS = %.2f(fossil_rss()/1000000.0) MB</br>
14641464
#endif
1465
- @ cgi_csrf_safe(0) = %d(cgi_csrf_safe(0))<br>
1465
+ (void)cgi_csrf_safe(2);
1466
+ switch( g.okCsrf ){
1467
+ case 1: {
1468
+ @ CSRF safety = Same origin<br>
1469
+ break;
1470
+ }
1471
+ case 2: {
1472
+ @ CSRF safety = Same origin, POST<br>
1473
+ break;
1474
+ }
1475
+ case 3: {
1476
+ @ CSRF safety = Same origin, POST, CSRF token<br>
1477
+ break;
1478
+ }
1479
+ default: {
1480
+ @ CSRF safety = unsafe<br>
1481
+ break;
1482
+ }
1483
+ }
1484
+
14661485
@ fossil_exe_id() = %h(fossil_exe_id())<br>
14671486
if( g.perm.Admin ){
14681487
int k;
14691488
for(k=0; g.argvOrig[k]; k++){
14701489
Blob t;
14711490
--- src/style.c
+++ src/style.c
@@ -1460,11 +1460,30 @@
1460 @ g.zRepositoryName = %h(g.zRepositoryName)<br>
1461 @ load_average() = %f(load_average())<br>
1462 #ifndef _WIN32
1463 @ RSS = %.2f(fossil_rss()/1000000.0) MB</br>
1464 #endif
1465 @ cgi_csrf_safe(0) = %d(cgi_csrf_safe(0))<br>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1466 @ fossil_exe_id() = %h(fossil_exe_id())<br>
1467 if( g.perm.Admin ){
1468 int k;
1469 for(k=0; g.argvOrig[k]; k++){
1470 Blob t;
1471
--- src/style.c
+++ src/style.c
@@ -1460,11 +1460,30 @@
1460 @ g.zRepositoryName = %h(g.zRepositoryName)<br>
1461 @ load_average() = %f(load_average())<br>
1462 #ifndef _WIN32
1463 @ RSS = %.2f(fossil_rss()/1000000.0) MB</br>
1464 #endif
1465 (void)cgi_csrf_safe(2);
1466 switch( g.okCsrf ){
1467 case 1: {
1468 @ CSRF safety = Same origin<br>
1469 break;
1470 }
1471 case 2: {
1472 @ CSRF safety = Same origin, POST<br>
1473 break;
1474 }
1475 case 3: {
1476 @ CSRF safety = Same origin, POST, CSRF token<br>
1477 break;
1478 }
1479 default: {
1480 @ CSRF safety = unsafe<br>
1481 break;
1482 }
1483 }
1484
1485 @ fossil_exe_id() = %h(fossil_exe_id())<br>
1486 if( g.perm.Admin ){
1487 int k;
1488 for(k=0; g.argvOrig[k]; k++){
1489 Blob t;
1490

Keyboard Shortcuts

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