fix(mod_whp_symlink): deny-by-default Options remap, refuse quoted lines; add probe test
Security review (2 HIGH): - Incomplete remap: only bare `All` was handled; `+All`/`-All`, `None +X`, `RunScripts` etc. passed through. The remap now matches every word against the full core keyword list and emits only known-safe names (prefix kept, core +/- mixing rules respected): any symlink-follow form -> SymLinksIfOwnerMatch, any exec-SSI form -> IncludesNOEXEC (only if allowed, else dropped), positive ExecCGI dropped, unknown words dropped. The line is always replaced by the normalised form, so the core never sees input words. - Parser differential: ap_getword_conf() unquotes, and the re-joined line was re-tokenised by the core. A line containing quote or backslash characters is now refused (config error -> 500, nothing enabled); emitted tokens are fixed keywords, so the join is unambiguous. scripts/tests/whp-symlink-module.test.sh probes 29 Options forms (+All, -All, All mixed with +/-, case and FollowSymlinks spelling variants, quoted, escaped, tab-separated) for cross-tenant symlink reads, SSI/CGI exec, refusal of quoted lines, and the swapped public_html owner guard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
1 parent
5fbc2e315e
commit
31e42ecbc2
2 files changed
+211
-36
No files matched your search
@@ -120,11 +120,25 @@ static void push(apr_array_header_t *out, char action, const char *w)
|
||||
action ? apr_pstrcat(out->pool, buf, w, NULL) : w;
|
||||
}
|
||||
|
||||
/* Push `name` with prefix `action` only when AllowOverride Options= permits
|
||||
* the option bits `bits`; used for every name this module synthesises. */
|
||||
static void push_if(apr_array_header_t *out, cmd_parms *cmd, char action,
|
||||
const char *name, int bits)
|
||||
{
|
||||
if ((cmd->override_opts & bits) == bits)
|
||||
push(out, action, name);
|
||||
}
|
||||
|
||||
/* Deny by default: every input word is matched against the complete list of
|
||||
* core Options keywords (server/core.c set_options); only known-safe names
|
||||
* are ever emitted, unknown words are dropped, and a line containing quote
|
||||
* or escape characters is refused outright, because ap_getword_conf()
|
||||
* unquotes and a re-joined line could tokenize differently in the core. */
|
||||
static const char *options_remap(cmd_parms *cmd, void *dummy, const char *l)
|
||||
{
|
||||
whp_srv_conf *sc;
|
||||
apr_array_header_t *words, *out;
|
||||
int i, follow_on = 0, merge = 0, changed = 0, owner_ok, noexec_ok;
|
||||
int i, follow_on = 0, changed = 0, any_merge = 0, absolute = 0;
|
||||
const char *orig = l;
|
||||
char *res;
|
||||
|
||||
@@ -134,24 +148,31 @@ static const char *options_remap(cmd_parms *cmd, void *dummy, const char *l)
|
||||
if (!sc || sc->remap != MODE_ON)
|
||||
return NULL;
|
||||
|
||||
if (strpbrk(l, "\"'\\")) {
|
||||
return "Options: quoted or escaped option names are not supported "
|
||||
"on this server (whp_symlink)";
|
||||
}
|
||||
|
||||
words = apr_array_make(cmd->temp_pool, 8, sizeof(char *));
|
||||
while (*l) {
|
||||
char *w = ap_getword_conf(cmd->temp_pool, &l);
|
||||
const char *n = w;
|
||||
if (!*w)
|
||||
continue;
|
||||
if (*n == '+' || *n == '-')
|
||||
n++;
|
||||
if (*n == '\0' || strpbrk(n, " \t\r\n\"'\\"))
|
||||
return "Options: malformed option word (whp_symlink)";
|
||||
if (words->nelts == 0 && n == w)
|
||||
absolute = 1;
|
||||
if (n != w)
|
||||
any_merge = 1;
|
||||
*(char **)apr_array_push(words) = w;
|
||||
if ((w[0] == '+' && !ap_cstr_casecmp(w + 1, "FollowSymLinks"))
|
||||
|| !ap_cstr_casecmp(w, "FollowSymLinks"))
|
||||
if (*w != '-' && (!ap_cstr_casecmp(n, "FollowSymLinks")
|
||||
|| !ap_cstr_casecmp(n, "All")))
|
||||
follow_on = 1;
|
||||
if (w[0] == '+' || w[0] == '-')
|
||||
merge = 1;
|
||||
}
|
||||
|
||||
/* Synthesised names are only emitted when AllowOverride Options=
|
||||
* permits them, so the rewritten line never fails the core's check. */
|
||||
owner_ok = (cmd->override_opts & OPT_SYM_OWNER) != 0;
|
||||
noexec_ok = (cmd->override_opts & OPT_INCLUDES) != 0;
|
||||
|
||||
out = apr_array_make(cmd->temp_pool, 8, sizeof(char *));
|
||||
for (i = 0; i < words->nelts; i++) {
|
||||
const char *w = ((char **)words->elts)[i];
|
||||
@@ -159,55 +180,93 @@ static const char *options_remap(cmd_parms *cmd, void *dummy, const char *l)
|
||||
if (*w == '+' || *w == '-')
|
||||
action = *w++;
|
||||
|
||||
if (!ap_cstr_casecmp(w, "FollowSymLinks")) {
|
||||
changed = 1;
|
||||
if (action != '-' && owner_ok)
|
||||
if (!ap_cstr_casecmp(w, "Indexes")) {
|
||||
push(out, action, "Indexes");
|
||||
}
|
||||
else if (!ap_cstr_casecmp(w, "MultiViews")) {
|
||||
push(out, action, "MultiViews");
|
||||
}
|
||||
else if (!ap_cstr_casecmp(w, "IncludesNOEXEC")) {
|
||||
push(out, action, "IncludesNOEXEC");
|
||||
}
|
||||
else if (!ap_cstr_casecmp(w, "SymLinksIfOwnerMatch")) {
|
||||
if (action == '-' && follow_on)
|
||||
changed = 1; /* "-SymLinksIfOwnerMatch +FollowSymLinks" */
|
||||
else
|
||||
push(out, action, "SymLinksIfOwnerMatch");
|
||||
}
|
||||
else if (!ap_cstr_casecmp(w, "SymLinksIfOwnerMatch")
|
||||
&& action == '-' && follow_on) {
|
||||
else if (!ap_cstr_casecmp(w, "FollowSymLinks")) {
|
||||
changed = 1;
|
||||
if (action != '-')
|
||||
push_if(out, cmd, action, "SymLinksIfOwnerMatch", OPT_SYM_OWNER);
|
||||
}
|
||||
else if (!ap_cstr_casecmp(w, "Includes")) {
|
||||
changed = 1;
|
||||
if (noexec_ok)
|
||||
push(out, action, "IncludesNOEXEC");
|
||||
changed = 1; /* exec-SSI never; NOEXEC if allowed */
|
||||
push_if(out, cmd, action, "IncludesNOEXEC", OPT_INCLUDES);
|
||||
}
|
||||
else if (!ap_cstr_casecmp(w, "ExecCGI")) {
|
||||
if (action == '-')
|
||||
push(out, action, w);
|
||||
push(out, action, "ExecCGI");
|
||||
else
|
||||
changed = 1;
|
||||
changed = 1; /* tier policy: never enable CGI */
|
||||
}
|
||||
else if (!ap_cstr_casecmp(w, "RunScripts")) {
|
||||
changed = 1;
|
||||
changed = 1; /* = MultiViews + ExecCGI */
|
||||
push(out, action, "MultiViews");
|
||||
if (action == '-')
|
||||
push_if(out, cmd, '-', "ExecCGI", OPT_EXECCGI);
|
||||
}
|
||||
else if (!ap_cstr_casecmp(w, "All") && !action) {
|
||||
else if (!ap_cstr_casecmp(w, "None")) {
|
||||
if (action || i != 0)
|
||||
changed = 1; /* invalid in the core; drop */
|
||||
else
|
||||
push(out, 0, "None");
|
||||
}
|
||||
else if (!ap_cstr_casecmp(w, "All")) {
|
||||
changed = 1;
|
||||
if (cmd->override_opts & OPT_INDEXES)
|
||||
push(out, 0, "Indexes");
|
||||
if (owner_ok)
|
||||
push(out, 0, "SymLinksIfOwnerMatch");
|
||||
if (noexec_ok)
|
||||
push(out, 0, "IncludesNOEXEC");
|
||||
if (!action && i != 0) {
|
||||
/* the core rejects this; drop it */
|
||||
}
|
||||
else if (action == '-') {
|
||||
push_if(out, cmd, '-', "Indexes", OPT_INDEXES);
|
||||
push_if(out, cmd, '-', "SymLinksIfOwnerMatch", OPT_SYM_OWNER);
|
||||
push_if(out, cmd, '-', "IncludesNOEXEC", OPT_INCLUDES);
|
||||
push_if(out, cmd, '-', "ExecCGI", OPT_EXECCGI);
|
||||
}
|
||||
else {
|
||||
/* bare All (first) or +All: the safe subset of All. A bare
|
||||
* All followed by +/- words becomes "None +x +y" (the core
|
||||
* accepts +/- after None); otherwise plain bare names. */
|
||||
char a = action;
|
||||
if (!action && any_merge) {
|
||||
push(out, 0, "None");
|
||||
a = '+';
|
||||
}
|
||||
push_if(out, cmd, a, "Indexes", OPT_INDEXES);
|
||||
push_if(out, cmd, a, "SymLinksIfOwnerMatch", OPT_SYM_OWNER);
|
||||
push_if(out, cmd, a, "IncludesNOEXEC", OPT_INCLUDES);
|
||||
}
|
||||
}
|
||||
else {
|
||||
push(out, action, w);
|
||||
changed = 1; /* unknown word: deny by default */
|
||||
ap_log_error(APLOG_MARK, APLOG_INFO, 0, cmd->server,
|
||||
"whp_symlink: %s:%d: dropped unknown Options word %s",
|
||||
cmd->directive->filename, cmd->directive->line_num, w);
|
||||
}
|
||||
}
|
||||
if (!changed)
|
||||
return NULL;
|
||||
|
||||
/* Always replace the line with the normalised, known-keyword-only form
|
||||
* (also when nothing was remapped), so the core never sees input words. */
|
||||
if (out->nelts == 0)
|
||||
res = merge ? "" : "None"; /* "" = no-op in core set_options */
|
||||
res = absolute ? "None" : ""; /* "" = no-op in core set_options */
|
||||
else
|
||||
res = apr_array_pstrcat(cmd->temp_pool, out, ' ');
|
||||
|
||||
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server,
|
||||
"whp_symlink: %s:%d: Options \"%s\" -> \"%s\"",
|
||||
cmd->directive->filename, cmd->directive->line_num,
|
||||
orig, res);
|
||||
if (changed)
|
||||
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server,
|
||||
"whp_symlink: %s:%d: Options \"%s\" -> \"%s\"",
|
||||
cmd->directive->filename, cmd->directive->line_num,
|
||||
orig, res);
|
||||
/* The core reads current->args again for its own invocation. */
|
||||
((ap_directive_t *)cmd->directive)->args = res;
|
||||
return NULL;
|
||||
|
||||
Reference in new issue
Block a user