mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Checked against the 2024 Confusion Attacks on Apache httpd
(blog.orange.tw, CVE-2024-38472 to -38477 and CVE-2024-39573, fixed in
2.4.60). The guide's examples were reverse proxies only, with no
RewriteRule, but each passed the WebSocket with ProxyPassMatch and $1 - a
request capture in a proxy target, the shape those attacks abuse - and in
the sub-URL example that rule looked for ^/sockjs while the requests come
to /wekan/sockjs, so its WebSocket never connected.
- Both examples pass the WebSocket with "ProxyPass ... upgrade=websocket"
on their fixed prefix (2.4.47+); no ProxyPassMatch remains.
- The guide asks for httpd 2.4.60 or newer, drops NameVirtualHost (a no-op
in 2.4) and the path in the sub-URL ServerName, which is not valid.
- A "What not to add" section: no RewriteRule or ProxyPassMatch with a
request capture in the target, no <Files>/<Location> ACL in front of
WeKan, AllowEncodedSlashes Off and MergeSlashes On, <Directory /> denied.
Verified with Apache 2.4.67: both virtual hosts parse, and in front of a
WebSocket server both pass HTTP and the WebSocket, at / and at /wekan;
the old sub-URL example fails its WebSocket ("Unexpected server response:
200"). tests/apacheReverseProxy.test.cjs pins it and fails on the old guide.
WeKan's own redirects stay on its origin (CAS checks the callback's origin
against ROOT_URL; the file and avatar redirects build their own paths), so
a backend-chosen Location cannot be steered elsewhere.
Thanks to xet7 !
85 lines
3.9 KiB
JavaScript
85 lines
3.9 KiB
JavaScript
'use strict';
|
|
|
|
// Regression coverage for #3001. The documented Apache configuration must be
|
|
// a reverse proxy only, never an Internet-facing forward proxy.
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const source = fs.readFileSync(
|
|
path.join(__dirname, '..', 'docs/Platforms/Webserver/Apache.md'),
|
|
'utf8',
|
|
);
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
test('every example virtual host explicitly disables forward proxying', () => {
|
|
const virtualHosts = [...source.matchAll(/<VirtualHost[^>]*>([\s\S]*?)<\/VirtualHost>/g)];
|
|
assert.strictEqual(virtualHosts.length, 2);
|
|
for (const [, body] of virtualHosts) {
|
|
assert.match(body, /^\s*ProxyRequests Off\s*$/m);
|
|
}
|
|
});
|
|
|
|
test('the guide never enables or grants wildcard access to a forward proxy', () => {
|
|
assert.doesNotMatch(source, /^\s*ProxyRequests On\s*$/m);
|
|
assert.doesNotMatch(source, /<Proxy\s+["']?\*["']?>/i);
|
|
});
|
|
|
|
test('the ineffective forwarding-depth workaround is rejected', () => {
|
|
assert.match(source, /`ProxyMaxForwards`[^\n]+does\s+not close an open proxy/);
|
|
});
|
|
|
|
// The 2024 Confusion Attacks
|
|
// (https://blog.orange.tw/posts/2024-08-confusion-attacks-en/): a request
|
|
// capture in a RewriteRule or ProxyPassMatch target reaches files outside the
|
|
// DocumentRoot or another proxy target, Apache's <Files>/<Location> name can
|
|
// differ from what the backend serves, and AllowEncodedSlashes On sent NTLM
|
|
// hashes on Windows. Fixed in httpd 2.4.60.
|
|
const configs = [...source.matchAll(/```ApacheConf\n([\s\S]*?)```/g)].map(m => m[1]).join('\n');
|
|
|
|
test('the guide asks for httpd 2.4.60, which fixes the Confusion Attacks', () => {
|
|
assert.match(source, /Apache httpd \*\*2\.4\.60 or newer\*\*/);
|
|
assert.match(source, /CVE-2024-38472 to CVE-2024-38477 and CVE-2024-39573/);
|
|
});
|
|
|
|
test('both examples pass the WebSocket with upgrade=websocket on a fixed prefix', () => {
|
|
const virtualHosts = [...source.matchAll(/<VirtualHost[^>]*>([\s\S]*?)<\/VirtualHost>/g)].map(m => m[1]);
|
|
assert.match(virtualHosts[0], /^\s*ProxyPass\s+"\/" "http:\/\/127\.0\.0\.1:3001\/" upgrade=websocket$/m);
|
|
// The sub-URL example's ProxyPassMatch looked for ^/sockjs while the
|
|
// requests arrive at /wekan/sockjs, so its WebSocket never connected.
|
|
assert.match(virtualHosts[1], /^\s*ProxyPass\s+"\/wekan" "http:\/\/127\.0\.0\.1:3001\/wekan" upgrade=websocket$/m);
|
|
for (const body of virtualHosts) {
|
|
// A ServerName is a host name; a path in it is not valid.
|
|
assert.match(body, /^\s*ServerName [a-z0-9.-]+$/m);
|
|
}
|
|
});
|
|
|
|
test('negative: no config builds a target from the request, or loosens path handling', () => {
|
|
assert.doesNotMatch(configs, /^\s*ProxyPassMatch\b/m, 'a request capture in a proxy target');
|
|
assert.doesNotMatch(configs, /^\s*RewriteRule\b/m, 'a request capture in a rewrite target');
|
|
assert.doesNotMatch(configs, /\[[^\]\n]*\bP\b[^\]\n]*\]/, 'a RewriteRule proxy flag');
|
|
assert.doesNotMatch(configs, /\$\d/, 'a backreference anywhere in a target');
|
|
assert.doesNotMatch(configs, /^\s*AllowEncodedSlashes\s+(On|NoDecode)\b/mi);
|
|
assert.doesNotMatch(configs, /^\s*MergeSlashes\s+Off\b/mi);
|
|
assert.doesNotMatch(configs, /<Files\b|<FilesMatch\b/i, 'an Apache-side filename ACL');
|
|
assert.doesNotMatch(configs, /<Directory\s+["']?\/["']?>[\s\S]*?Require all granted/i);
|
|
assert.doesNotMatch(source, /^\s*NameVirtualHost\b/m, 'a directive 2.4 only warns about');
|
|
});
|
|
|
|
test('the guide says what not to add, and why', () => {
|
|
const section = source.slice(source.indexOf('### c) What not to add'), source.indexOf('## 5) Enable your site'));
|
|
for (const topic of [/RewriteRule.*ProxyPassMatch|ProxyPassMatch.*RewriteRule/s, /`%3F`/, /DocumentRoot/,
|
|
/<Files>.*<Location>/s, /AllowEncodedSlashes/, /MergeSlashes/, /CVE-2024-38472/, /<Directory \/>/, /\/usr\/share/]) {
|
|
assert.match(section, topic);
|
|
}
|
|
});
|
|
|
|
console.log(`\napacheReverseProxy: ${passed} tests passed`);
|