]> cat aescling's git repositories - httpd-execline.git/commitdiff
Protect headers we always send from override
authorcat æscling <11325618-aescling@users.noreply.gitlab.com>
Wed, 26 Jul 2023 00:33:13 +0000 (20:33 -0400)
committercat æscling <11325618-aescling@users.noreply.gitlab.com>
Wed, 26 Jul 2023 01:25:21 +0000 (21:25 -0400)
The extensibility is not great because execline makes lists difficult.
There are no native lists, not to mention any kind of list.contains

README.md
visible-to-httpd/binaries/http-print-header-files.execline
visible-to-httpd/binaries/httpd.execline

index a209adca602c9053a671ee54d37d2d5f2dc08698..a53e7f1bf4a6a42f3e9073f63f4fc015c67240ad 100644 (file)
--- a/README.md
+++ b/README.md
@@ -153,7 +153,9 @@ scheme, and a `Content-Type` file, to override any other mechanism for
 determining the Content-Type to send to the client.
 
 Note that a `Content-Type` file in the `headers` folder is always
-ignored.
+ignored. This is also true for the other required or recommended
+HTTP 1.1 headers always sent by httpd.execline, namely
+`Content-Length`, `Date`, and `Last-Modified`.
 
 a former official website for `httpd-execline.eerie.garden`
 used to redirect to this github repository, thanks to
index 9886081353abef5b41edd05c6323386653797961..3b5980a8353e30f71828bd2231599fcccd76d8d3 100755 (executable)
@@ -6,7 +6,7 @@
 # instances of ${hostname} and ${resource} are substituted with the provided
 # host and resource from the request
 #
-# the script will refuse to override the Content-Type header
+# the script will refuse to override any header already set by httpd.execline
 #
 # execs into self in order to retain an environment variable which marks
 # whether a certain header has been overridden or not
@@ -30,15 +30,20 @@ emptyenv -P
 # performs `basename ${header_file}`
 backtick -E -n header_name {
        pipeline { s6-echo -n -- ${header_file} }
-       sed "s@.*/([^/]*)@\\1@"
+       pipeline { sed "s@.*/([^/]*)@\\1@" }
+       tr -d " \t\r\n" # paranoid
 }
 
+# ignore protected headers
 ifelse {
-       pipeline { s6-echo -n -- \${header_name} }
-       grep -s -i '^[  ]*Content-Type[         ]*$' # paranoid whitespace matching
+       backtick -E -n header_name_lowercase {
+               pipeline { s6-echo -n -- ${header_name} }
+               tr A-Z a-z
+       }
+       s6-test -v httpd_execline_protected_header_${header_name_lowercase}
 }
 {
-       foreground { log.execline "refusing to override Content-Type header" }
+       foreground { log.execline "WARNING: configuration error: ignoring protected header: \""${header_name}\" }
        http-print-header-directories.execline ${@}
 }
 
@@ -63,12 +68,9 @@ define header_substitution_script
 }
 s6-echo -n -- "
 
-# we’ll strip out `\r`s and `\n`s from filenames and file contents, in
+# we’ll strip out `\r`s and `\n`s from file contents, in
 # case the configuration should ever be made in a mischevious way
-if {
-       pipeline { s6-echo -n -- ${header_name}": " }
-       tr -d "\r\n"
-}
+if {  s6-echo -n -- ${header_name}": " }
 if {
        backtick -E -n unparsed_header_contents {
                pipeline { cat ${header_file} }
index 275f8953a5cae058fde29767945dc6bc176cfc2b..3134664827d8f571f266be92913ce06a61d670f0 100755 (executable)
@@ -217,7 +217,14 @@ if -X -n -t {
        # Security Policy; for the latter, consider HTTP 301 redirects
        #
        # be warned!! we do not validate these overrides!
-       backtick -n extra_headers { http-get-extra-headers.execline }
+       backtick -n extra_headers {
+               export httpd_execline_protected_header_content-length ""
+               export httpd_execline_protected_header_content-type ""
+               export httpd_execline_protected_header_date ""
+               export httpd_execline_protected_header_last-modified ""
+
+               http-get-extra-headers.execline
+       }
 
        backtick -D "200 ok" -n status_code_and_message {
                if { s6-test -r configuration/overrides/${resource}/status_code }