Fossil SCM

Do not allow caching of generated HTML content, as such content will usually contain a nonce which ought not be repeated.

drh 2023-06-22 17:09 trunk
Commit bdde964e06128a02cf5d04d7542399b144ed487076a5e792bbf2c29eb4a436dc
1 file changed +8 -5
+8 -5
--- src/cgi.c
+++ src/cgi.c
@@ -497,11 +497,17 @@
497497
blob_appendf(&hdr, "X-UA-Compatible: IE=edge\r\n");
498498
}else{
499499
assert( rangeEnd==0 );
500500
blob_appendf(&hdr, "Status: %d %s\r\n", iReplyStatus, zReplyStatus);
501501
}
502
- if( etag_tag()[0]!=0 ){
502
+ if( etag_tag()[0]!=0
503
+ && iReplyStatus==200
504
+ && strcmp(zContentType,"text/html")==0
505
+ ){
506
+ /* Do not cache HTML replies as those will have been generated and
507
+ ** will likely, therefore, contains a nonce and we want that nonce to
508
+ ** be different every time. */
503509
blob_appendf(&hdr, "ETag: %s\r\n", etag_tag());
504510
blob_appendf(&hdr, "Cache-Control: max-age=%d\r\n", etag_maxage());
505511
if( etag_mtime()>0 ){
506512
blob_appendf(&hdr, "Last-Modified: %s\r\n",
507513
cgi_rfc822_datestamp(etag_mtime()));
@@ -518,11 +524,11 @@
518524
blob_appendf(&hdr, "%s", blob_buffer(&extraHeader));
519525
}
520526
521527
/* Add headers to turn on useful security options in browsers. */
522528
blob_appendf(&hdr, "X-Frame-Options: SAMEORIGIN\r\n");
523
- /* This stops fossil pages appearing in frames or iframes, preventing
529
+ /* The previous stops fossil pages appearing in frames or iframes, preventing
524530
** click-jacking attacks on supporting browsers.
525531
**
526532
** Other good headers would be
527533
** Strict-Transport-Security: max-age=62208000
528534
** if we're using https. However, this would break sites which serve different
@@ -534,13 +540,10 @@
534540
**
535541
** These headers are probably best added by the web server hosting fossil as
536542
** a CGI script.
537543
*/
538544
539
- /* Content intended for logged in users should only be cached in
540
- ** the browser, not some shared location.
541
- */
542545
if( iReplyStatus!=304 ) {
543546
blob_appendf(&hdr, "Content-Type: %s%s\r\n", zContentType,
544547
content_type_charset(zContentType));
545548
if( fossil_strcmp(zContentType,"application/x-fossil")==0 ){
546549
cgi_combine_header_and_body();
547550
--- src/cgi.c
+++ src/cgi.c
@@ -497,11 +497,17 @@
497 blob_appendf(&hdr, "X-UA-Compatible: IE=edge\r\n");
498 }else{
499 assert( rangeEnd==0 );
500 blob_appendf(&hdr, "Status: %d %s\r\n", iReplyStatus, zReplyStatus);
501 }
502 if( etag_tag()[0]!=0 ){
 
 
 
 
 
 
503 blob_appendf(&hdr, "ETag: %s\r\n", etag_tag());
504 blob_appendf(&hdr, "Cache-Control: max-age=%d\r\n", etag_maxage());
505 if( etag_mtime()>0 ){
506 blob_appendf(&hdr, "Last-Modified: %s\r\n",
507 cgi_rfc822_datestamp(etag_mtime()));
@@ -518,11 +524,11 @@
518 blob_appendf(&hdr, "%s", blob_buffer(&extraHeader));
519 }
520
521 /* Add headers to turn on useful security options in browsers. */
522 blob_appendf(&hdr, "X-Frame-Options: SAMEORIGIN\r\n");
523 /* This stops fossil pages appearing in frames or iframes, preventing
524 ** click-jacking attacks on supporting browsers.
525 **
526 ** Other good headers would be
527 ** Strict-Transport-Security: max-age=62208000
528 ** if we're using https. However, this would break sites which serve different
@@ -534,13 +540,10 @@
534 **
535 ** These headers are probably best added by the web server hosting fossil as
536 ** a CGI script.
537 */
538
539 /* Content intended for logged in users should only be cached in
540 ** the browser, not some shared location.
541 */
542 if( iReplyStatus!=304 ) {
543 blob_appendf(&hdr, "Content-Type: %s%s\r\n", zContentType,
544 content_type_charset(zContentType));
545 if( fossil_strcmp(zContentType,"application/x-fossil")==0 ){
546 cgi_combine_header_and_body();
547
--- src/cgi.c
+++ src/cgi.c
@@ -497,11 +497,17 @@
497 blob_appendf(&hdr, "X-UA-Compatible: IE=edge\r\n");
498 }else{
499 assert( rangeEnd==0 );
500 blob_appendf(&hdr, "Status: %d %s\r\n", iReplyStatus, zReplyStatus);
501 }
502 if( etag_tag()[0]!=0
503 && iReplyStatus==200
504 && strcmp(zContentType,"text/html")==0
505 ){
506 /* Do not cache HTML replies as those will have been generated and
507 ** will likely, therefore, contains a nonce and we want that nonce to
508 ** be different every time. */
509 blob_appendf(&hdr, "ETag: %s\r\n", etag_tag());
510 blob_appendf(&hdr, "Cache-Control: max-age=%d\r\n", etag_maxage());
511 if( etag_mtime()>0 ){
512 blob_appendf(&hdr, "Last-Modified: %s\r\n",
513 cgi_rfc822_datestamp(etag_mtime()));
@@ -518,11 +524,11 @@
524 blob_appendf(&hdr, "%s", blob_buffer(&extraHeader));
525 }
526
527 /* Add headers to turn on useful security options in browsers. */
528 blob_appendf(&hdr, "X-Frame-Options: SAMEORIGIN\r\n");
529 /* The previous stops fossil pages appearing in frames or iframes, preventing
530 ** click-jacking attacks on supporting browsers.
531 **
532 ** Other good headers would be
533 ** Strict-Transport-Security: max-age=62208000
534 ** if we're using https. However, this would break sites which serve different
@@ -534,13 +540,10 @@
540 **
541 ** These headers are probably best added by the web server hosting fossil as
542 ** a CGI script.
543 */
544
 
 
 
545 if( iReplyStatus!=304 ) {
546 blob_appendf(&hdr, "Content-Type: %s%s\r\n", zContentType,
547 content_type_charset(zContentType));
548 if( fossil_strcmp(zContentType,"application/x-fossil")==0 ){
549 cgi_combine_header_and_body();
550

Keyboard Shortcuts

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