beyondcode / beyondcode/herd-community
[Bug]: Herd PHP binary hardcodes APP_ENV=local via getenv(), breaking PHPUnit CSRF bypass
- Lingua principale
- Nessun dato sulla lingua
- Stelle
- 122
- Fork
- 1
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
### Platform
macOS
### Operating system version
macOS Sequoia 15.2 (24C101)
### System architecture
ARM64 (M1, M2, etc)
### Herd Version
1.26.0
### PHP Version
8.5.1
### Bug description
The bug: Herd's PHP binary hardcodes `APP_ENV=local` via putenv() at startup. This prevents PHPUnit's `` from working because the dotenv immutable repository reads `getenv()` first and finds local.
The fix for Herd: Don't set APP_ENV in the CLI binary at all (it's only useful for FPM/web context), or set it only when running under FPM, not CLI.
The workaround : Add `` to phpunit.xml, which overrides `$_SERVER` and gets picked up before the `PutenvAdapter`.
### Steps to reproduce
```php
test('getenv APP_ENV should not be set by the PHP binary itself', function () {
// Herd's PHP binary injects APP_ENV=local into getenv() before any code runs.
// This prevents PHPUnit's from taking effect because dotenv's
// immutable repository reads getenv() first and locks in 'local'.
expect(getenv('APP_ENV'))->toBe('testing');
});
```
Adding ` ` to phpunit.xml makes the test pass
1. Create any Laravel project served by Herd
2. Run php -r "echo getenv('APP_ENV');" — outputs local
3. Run env -i HOME=$HOME PATH=$PATH php -r "echo getenv('APP_ENV') ?: 'not set';" — outputs not set (proving it's not in the shell environment)
4. Run Herd's PHP with no ini files: "/Users/brian/Library/ApplicationSupport/Herd/bin/php" -n -r "echo getenv('APP_ENV') ?: 'not set';" — still outputs local
5. Run php artisan test — all POST-based feature tests fail with 419 (CSRF token mismatch)
### Relevant log output
```shell
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Inizia riproducendo il comportamento con il binario PHP di Herd usando `php -n -r "echo getenv('APP_ENV') ?: 'not set';"`, quindi confrontalo con il comando `env -i` mostrato nel report. Verifica il comportamento con `phpunit.xml` e `php artisan test`; il lavoro è completato quando CLI PHP non forza più `APP_ENV=local` e i test basati su POST non falliscono più con 419.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- php
- Ambito
- cli, devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100