Skip to content

Add a new SetEnvFromFile directive that reads internal environment va… - #750

Open
cisbiceanu wants to merge 1 commit into
apache:trunkfrom
cisbiceanu:mod-env-setEnvFromFile
Open

Add a new SetEnvFromFile directive that reads internal environment va…#750
cisbiceanu wants to merge 1 commit into
apache:trunkfrom
cisbiceanu:mod-env-setEnvFromFile

Conversation

@cisbiceanu

@cisbiceanu cisbiceanu commented Sep 9, 2026

Copy link
Copy Markdown

mod_env: Add SetEnvFromFile directive

Add a new SetEnvFromFile directive that reads internal environment
variables from a file of "name=value" lines at configuration time.
Each entry is stored in the same per-directory table used by SetEnv,
so the values merge and reach r->subprocess_env identically and are
available to CGI, SSI, logging and other consumers.

The file is read once when the configuration is parsed. Blank lines
and '#' comments are ignored, surrounding whitespace is stripped, and
a line without '=' sets the variable to an empty string. A line ending
in a backslash is continued on the next line, as in the main
configuration files. A line with no variable name (e.g. beginning with
'=') is skipped with a warning. Relative paths are resolved against
ServerRoot. A missing or unreadable file fails configuration with an
error, consistent with other file-backed directives.

Unlike SetEnv, SetEnvFromFile reads the contents of a file into the
environment, so it is restricted to the main server configuration
(RSRC_CONF | ACCESS_CONF) and is not permitted in .htaccess. This
prevents an untrusted author from reading any file the server can
read into the environment.

Because SetEnvFromFile and SetEnv write the same table, precedence
follows configuration order (last writer wins), matching existing
SetEnv semantics.

  • modules/metadata/mod_env.c: Add add_env_module_vars_from_file() and
    the SetEnvFromFile (RSRC_CONF | ACCESS_CONF, TAKE1) directive; warn
    (AH10624) on a line with no variable name.
  • docs/manual/mod/mod_env.xml: Document SetEnvFromFile, including the
    backslash continuation and the .htaccess restriction.
  • docs/log-message-tags/next-number: Reserve AH10624.
  • changes-entries/mod_env_setenvfromfile.txt: Add entry.
  • test/modules/metadata/test_002_setenvfromfile.py, env.py: Add pyhttpd
    tests for parsing (including whitespace and line continuation), the
    malformed-line warning, rejection in .htaccess, and failure on a
    missing file.

…riables from a file of "name=value" lines at configuration time. Each entry is stored in the same per-directory table used by SetEnv, so the values merge and reach r->subprocess_env identically and are available to CGI, SSI, logging and other consumers.
@cisbiceanu
cisbiceanu force-pushed the mod-env-setEnvFromFile branch from 8406019 to aa364b5 Compare September 10, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant