Skip to content

Load .env from the repository root on every platform and make OAuth endpoints optional - #7

Merged
valzargaming merged 2 commits into
mainfrom
claude/config-startup
Nov 6, 2026
Merged

valzargaming merged 2 commits into
mainfrom
claude/config-startup

Conversation

@valzargaming

Copy link
Copy Markdown
Member

Requested by Val · project thread

Problem

  • loadEnvConfig() built the dotenv path as __DIR__ . '\..\..\'. That only resolves on Windows; on Linux php run.php died with InvalidPathException: Unable to read any of the environment file(s) at [.../src/VerifierServer\..\..\/.env] before binding a socket (reproduced). It also created the default .env in the working directory while reading it from the repository root, read DB_* keys the shipped example comments out (undefined index warnings), and used die().
  • run.php passed getenv('SS14_OAUTH2_CLIENT_ID') etc. straight into string parameters. Unset variables give false, which is a TypeError under strict_types, so a plain verifier could not start without SS14 and Discord OAuth credentials.
  • The OAuth2 CSRF state was uniqid(), which is time-based and guessable.

Change

  • .env is resolved relative to the repository root (or a directory passed to loadEnvConfig()), every returned key has a default, real environment variables keep precedence over the file, and the default-token guard throws instead of calling die().
  • run.php registers the /ss14wa and /dwa endpoints only when both credentials are set. example.env and README describe this and comment out the MySQL block by default.
  • state is bin2hex(random_bytes(16)).

Not changed here, but worth a follow-up: the OAuth2 sessions are keyed by client IP, so users behind one NAT share a session and ?user leaks the previous visitor's profile; and the token exchange uses blocking cURL inside the event loop. If the Discord login work in Civ13 reuses /dwa, it should move to cookie-based sessions first.

Compatibility with Civilizationbot

The bot constructs Server/PersistentState directly from its own getenv() values and never calls loadEnvConfig() in filesystem mode, so it is unaffected. Its integration call pattern was replayed against this branch and passed.

Verification

php scripts/lint.php                                   # Parsed 29 PHP files with PHP 8.3.6
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/isolated   # OK (10 tests, 49 assertions)

New tests/isolated/EnvConfigTest.php. Also confirmed loadEnvConfig() now runs from a foreign working directory on Linux.


Generated by Claude Code

…ndpoints optional

loadEnvConfig() built the dotenv path with backslashes
(__DIR__ . '\..\..\'), which only resolves on Windows: on Linux
run.php died with InvalidPathException before binding a socket. It also
created the default .env in the working directory while reading it from
the repository root, read DB_* keys that the shipped example comments
out (undefined index warnings in filesystem mode), and called die().

The file is now resolved relative to the repository root (or a directory
passed in), every returned key has a default, real environment variables
keep precedence over the file, and the default-token guard throws.

run.php required SS14 and Discord OAuth2 credentials even for a plain
verifier: getenv() returns false, which is a TypeError under
strict_types. The endpoints are now registered only when both halves are
set. The OAuth2 CSRF state is generated with random_bytes instead of
uniqid(), which is time-based and guessable.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WTP2S4qKEFT8a6a6yFEL4
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WTP2S4qKEFT8a6a6yFEL4
Copilot AI balanced review requested due to automatic review settings November 6, 2026 11:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@valzargaming valzargaming self-assigned this Nov 6, 2026

Copy link
Copy Markdown
Member Author

2026-11-06: head 4302e0b. Local: php scripts/lint.php (29 files) and ./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/isolated OK (10 tests, 49 assertions); loadEnvConfig() confirmed to run from a foreign working directory on Linux. CI: https://github.com/Valgorithms/Verifier-server/actions/runs/42212487663 passed on PHP 8.2 to 8.5. Not verified: live run.


Generated by Claude Code

@valzargaming
valzargaming merged commit aa8ab4c into main Nov 6, 2026
4 checks passed
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.

3 participants