# Security, Validation & Session Improvements
## Changes
* **Hardened IP/CIDR validation**
* Properly handles invalid IP addresses and CIDR ranges during API key
creation.
* Invalid IP/CIDR data now fails safely instead of causing a 500 error.
* **Improved reCAPTCHA error handling**
* Handles network and verification failures gracefully.
* Fixed undefined result notices and removed duplicate checks.
* **Added file permission activity logging**
* File permission (`chmod`) changes are now recorded in the activity
log.
* **Removed duplicate 2FA middleware**
* Cleaned up duplicate `RequireTwoFactorAuthentication` registration
from API routes.
* **Improved session revocation on password changes**
* Password changes now invalidate other active sessions.
* Rotates the `remember_token` and removes stale database sessions where
applicable.
* Applies consistently across password resets and user password changes.
* **Reduced unnecessary public storage access**
* Disabled automatic public storage routes for the local filesystem disk
to reduce the attack surface.
* **Hardened file manager request validation**
* Added strict validation for file permission modes.
* Fixed optional `root` validation rules.
* Added length limits for file paths, roots, and file/folder names.
* **Hardened mount source and target path validation**
* Prevents path traversal and subpath-based bypasses in mount source and
target validation.
* Handles trailing slashes and normalized paths correctly.
* Prevents mounts from targeting protected subdirectories, such as
another server's volume directory.
Changes the panel's default `Referrer-Policy` from
`no-referrer-when-downgrade` to `strict-origin-when-cross-origin`.
Prevents path and query string being sent in `Referrer`, so Google don't
get our tasty password reset url tokens.
Nothing I could find in panel reads a referrer cross-origin, and Wings
checks Origin not Referrer.
## Problem
An extension built with the SDK Vite preset whose lazy screens share a
module requests its shared chunk from the site root. For example
`/chunk.api.Hb1egxRz.js` returns the single page app shell (status 200,
`text/html`), and the browser logs `Failed to load module script:
Expected a JavaScript module script but the server responded with a MIME
type of "text/html"`. The extension still works, because the real
imports are relative, but every page load that touches such a screen
produces failing requests and console errors.
## Reproduction
1. Scaffold an extension with `php artisan p:extension:make demo`.
2. Register two screens with `screens.register('a', () =>
import('./A'))` and `screens.register('b', () => import('./B'))`, where
both import the same helper module.
3. Build it and enable it, then open one of the screens with the browser
network panel open.
The built `dist/client.js` starts with a `__vite__mapDeps` list of bare
chunk file names. Vite's preload helper resolves those names against the
document, not against the bundle.
## Root cause
Vite emits a `modulepreload` dependency map for dynamic imports. The
preset does not turn it off, and the helper's base is the page URL, so
the extension's chunk names resolve to the site root.
## Fix
Set `build.modulePreload` to `false` in `defineExtensionConfig`. Chunks
import each other with relative URLs, which already resolve against the
bundle, so nothing else changes. Preloading is only a hint.
## Testing
* New test in `packages/sdk/vite.spec.ts` builds an entry with two lazy
imports that share a module and asserts that the output contains no
preload map. It fails before the change and passes after it.
* `npx vitest run packages/sdk/vite.spec.ts` passes.
* Checked in a browser: the failing requests for the shared chunk
disappear and the screens still load.
## Compatibility considerations
Extensions rebuilt with the new preset lose a performance hint only.
Existing builds keep working as before.
## Problem
`packages/sdk/openapi.spec.ts` ("extracts all four extension API areas
without matching another extension") fails on PHP 8.3 with `Call to
undefined function mb_trim()` from
`scripts/generate-extension-openapi.php`. `composer.json` allows PHP
`^8.3`, but `mb_trim()` only exists natively from PHP 8.4. The frontend
job of the Tests workflow uses PHP 8.4, so the failure is not visible
there.
## Reproduction
On PHP 8.3 (for example `shivammathur/setup-php` with `php-version:
8.3`) run `npm ci` and `npm test`. One test fails with `PHP Fatal error:
Uncaught Error: Call to undefined function mb_trim() in
scripts/generate-extension-openapi.php:76`.
## Root cause
The script is meant to run standalone, and it only loads the Composer
autoloader when YAML input or output is involved. The autoloader is what
provides the `mb_trim()` polyfill, so the JSON only path calls an
undefined function on PHP 8.3.
## Fix
Use `trim()` for the generated API title. The title is built from the
original title, a fixed separator and a validated extension id, so ASCII
whitespace trimming gives the same result and no longer depends on the
polyfill.
## Testing
* `npx vitest run packages/sdk/openapi.spec.ts` on PHP 8.3: the
extraction test now passes. (The second test in that file also fails on
my Windows machine for a separate reason that does not occur on Linux,
so it is not part of this change.)
* Linux CI on PHP 8.3 reproduced the original failure as the only
failing frontend test.
## Compatibility considerations
None. The output is the same for any normal title, which cannot start
with Unicode only whitespace.
## Problem
`Tests\Integration\Console\SchedulerTest` (telemetry is scheduled and
sent only when enabled, dataset true) fails when the whole integration
suite runs, with `Failed asserting that actual size 22 matches expected
size 2`. It passes when the file is run on its own.
## Reproduction
Run `vendor/bin/pest tests/Integration` on a fresh checkout of the 2.0
development branch with the settings from `.env.ci` (it fails the same
way on Linux with PHP 8.3 and 8.4 against MariaDB 11 and MySQL 8, and on
Windows). Run `vendor/bin/pest
tests/Integration/Console/SchedulerTest.php` alone and it passes.
## Root cause
The test creates one node and then asserts that exactly two HTTP
requests were recorded: the telemetry request and the request for that
node. When the scheduler test runs inside the full suite, other
integration tests have already left committed node rows in the database
(21 nodes existed when the test ran). The telemetry job fetches system
information from every node, so each of those nodes adds another
request. Only the telemetry URL was faked, so the extra requests were
real outbound connection attempts to the random addresses of the
leftover factory nodes.
## Fix
* Fake every other URL with an empty successful response, so the test
can never make real network requests.
* Assert what the test is about, which is that exactly one telemetry
request is sent, instead of the total number of requests. The existing
assertion that the telemetry payload contains the created node is kept.
## Testing
* `vendor/bin/pest tests/Integration/Console/SchedulerTest.php` passes.
* The full `vendor/bin/pest tests/Integration` run no longer reports
this test as failed (on Windows the remaining failures there come from
missing `pdo_sqlite` and POSIX file modes and are unrelated).
## Compatibility considerations
Test only change. No application code, configuration or behaviour is
touched.
Fixes two SFTP lockout bugs:
- `ad374661f` moved the server lookup after the password check, so fake
server identifiers bypassed the rate limit.
- `24f340c9a` keyed the lockout on server + Wings IP, so anyone could
lock every user out of a server.
Unknown servers are now rejected before any credential check, and the
lockout is keyed on the normalised username + resolved server UUID.