Sperre andere Methoden als GET/HEAD auf den Shop-Hosts bei X-Forwarded-Proto http
CI Feature / test (push) Successful in 2m2s
Deploy Test / test (push) Successful in 1m52s
Deploy Test / deploy (push) Successful in 30s

Setzt die Synology ausdrücklich X-Forwarded-Proto: http, enden POST, PUT, DELETE
usw. auf lara-und-felix.de, www.lara-und-felix.de und www.laraundfelix.de mit
403 im Nginx, bevor Laravel die Anfrage sieht. GET und HEAD werden wie bisher
per 301 weitergeleitet. Unverändert bleiben HTTPS (Stripe-Webhook), die
ACME-Ausnahme, dev.laraundfelix.de und der Zugriff ohne X-Forwarded-Proto
(Health-Check).

Mit nginx 1.27.5 in 49 Fällen geprüft; Reihenfolge und Zusagen in
NginxConfigTest, Betrieb in docs/betrieb/DEPLOYMENT.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-22 12:33:39 +01:00
1 parent acb88e4a1d
commit b8c5c68887
3 files changed
+54 -8

No files matched your search

+37 -2
View File
@@ -66,9 +66,10 @@ public function test_alias_hosts_are_redirected_to_the_fixed_canonical_domain():
{
$config = $this->config();
$this->assertStringContainsString('if ($luf_canonical_redirect) {', $config);
$this->assertStringContainsString('if ($luf_canonical_redirect = 1) {', $config);
$this->assertStringContainsString('return 301 https://lara-und-felix.de$request_uri;', $config, 'Fest verdrahtetes Ziel, Pfad und Query-String aus $request_uri.');
$this->assertSame(1, preg_match_all('/^\s*return\s+30\d\s/m', $config), 'Es gibt genau eine Weiterleitung.');
$this->assertSame(2, preg_match_all('/^\s*return\s+\d{3}\b/m', $config), 'Nur Weiterleitung und Sperre antworten selbst.');
$this->assertDoesNotMatchRegularExpression('/return\s+30\d\s+[^;]*\$(host|http_host|http_x_forwarded_host|scheme)/', $config, 'Das Ziel darf nicht aus Anfragewerten entstehen.');
}
@@ -92,6 +93,40 @@ public function test_only_get_and_head_are_redirected(): void
}
}
/**
* @return list<string> Zeilen der map, die andere Methoden sperren (Wert 2)
*/
private function blockRules(): array
{
return array_values(array_filter($this->redirectMap(), fn (string $line) => str_ends_with($line, '" 2;')));
}
public function test_other_methods_on_the_three_shop_hosts_end_at_nginx_when_proxy_says_http(): void
{
$config = $this->config();
$rules = $this->blockRules();
$this->assertCount(1, $rules);
$rule = $rules[0];
$this->assertStringStartsWith('"~*^[^|]*\|', $rule, 'Jede Methode, die nicht vorher als GET/HEAD entschieden wurde.');
$this->assertStringContainsString('\|\s*http\s*(,[^|]*)?\|', $rule, 'Nur bei ausdrücklichem X-Forwarded-Proto http (erster Wert).');
foreach (['www\.lara-und-felix', 'www\.laraundfelix', '(www\.lara-und-felix|www\.laraundfelix|lara-und-felix)\.de'] as $host) {
$this->assertStringContainsString($host, $rule);
}
$this->assertStringNotContainsString('dev', $rule, 'dev.laraundfelix.de bleibt unverändert.');
$this->assertStringNotContainsString('https', $rule);
$this->assertMatchesRegularExpression('/^\s*if\s*\(\$luf_canonical_redirect = 2\)\s*\{\s*return\s+403;\s*\}/m', $config, 'Die Sperre antwortet in nginx, bevor die Anfrage Laravel erreicht.');
$this->assertDoesNotMatchRegularExpression('/\$luf_canonical_redirect = 2\)\s*\{[^}]*(fastcgi_pass|proxy_pass)/', $config);
}
public function test_block_rule_comes_after_acme_exception_and_the_redirects(): void
{
// nginx nimmt den ersten passenden Regex-Eintrag: Ausnahme, dann GET/HEAD-Weiterleitungen, zuletzt die Sperre.
$values = array_map(fn (string $line) => rtrim(substr($line, (int) strrpos($line, ' ') + 1), ';'), $this->redirectMap());
$this->assertSame(['0', '0', '1', '1', '1', '2'], $values, 'Reihenfolge: default, ACME, drei Weiterleitungen, Sperre.');
}
public function test_acme_challenge_is_excluded_before_any_redirect_rule(): void
{
$acme = null;
@@ -100,7 +135,7 @@ public function test_acme_challenge_is_excluded_before_any_redirect_rule(): void
if ($acme === null && str_contains($line, '/\.well-known/acme-challenge/') && str_ends_with($line, '" 0;')) {
$acme = $index;
}
if ($firstRedirect === null && str_ends_with($line, '" 1;')) {
if ($firstRedirect === null && (str_ends_with($line, '" 1;') || str_ends_with($line, '" 2;'))) {
$firstRedirect = $index;
}
}