# 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.
## Problem
`vendor/bin/rector --dry-run` reports three files that would change,
which fails the Static Analysis job of the Tests workflow.
## Reproduction
Run `vendor/bin/rector --dry-run --no-progress-bar` on a clean checkout
with PHP 8.4, as the workflow does. Rector lists `PasswordBroker.php`,
`PasswordBrokerManager.php` and `FileController.php`. With PHP 8.3 the
command reports nothing, because some rules depend on the running PHP
version.
## Root cause
Recent changes in these three files were merged without running Rector,
so they differ from the style the project enforces.
## Fix
Apply exactly the changes Rector prints:
* `PasswordBroker`: compare the callback with `instanceof Closure`
instead of `!== null`.
* `PasswordBrokerManager`: use `throw_unless` and `throw_if` with the
exception class string.
* `FileController`: name the caught exception
`$daemonConnectionException` after its type.
## Testing
* `vendor/bin/rector --dry-run` no longer reports changes locally, and
PHPStan and Pint still pass.
* The authentication integration tests and the server file integration
tests pass (86 tests).
* I could not run Rector under PHP 8.4 locally, so the Static Analysis
job of this pull request is the confirmation.
## Compatibility considerations
Behaviour is unchanged. The `instanceof Closure` check is stricter than
a null check only for callbacks that are not closures, and the parameter
is already typed as a nullable closure.
The API key creation endpoint checks that a user has fewer than 25 keys
before creating a new one. The problem is that the count was read from
an eager-loaded collection (`$user->apiKeys->count()`) with no lock
held, so concurrent requests could both pass the check and each create a
key, pushing the user past the 25-key cap.
The fix wraps the count check and key creation in a single database
transaction with `lockForUpdate()` on the query. Only one request at a
time can evaluate and modify the count, closing the race window.
### Proof of Concept
Run this in the browser console while authenticated with a user that has
24 API keys:
```js
(async () => {
const makeKey = (desc) => fetch('/api/client/account/api-keys', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'X-XSRF-TOKEN':
decodeURIComponent(document.cookie.match(/XSRF-TOKEN=([^;]+)/)[1]),
},
body: JSON.stringify({ description: desc, allowed_ips: [] }),
});
const [r1, r2] = await Promise.all([makeKey('0024'), makeKey('0025')]);
console.log('0024:', r1.status, (await r1.text()).slice(0, 200));
console.log('0025:', r2.status, (await r2.text()).slice(0, 200));
})();
```
On the old code, both requests can return 200 (you may need to run this
a few times to hit the race window). After the fix, the second request
correctly returns a 400 error.
This change applies a rate limit to account email changes to prevent
enumeration on the system. The throttle is applied at the account level.
Administrators can still update an account's email address manually to
bypass this restriction if/when necessary.
- Fixes issue where the panel would create activity logs even when the
value didn't change
- Log an empty string instead of displaying "null" when the variable is
empty
Closes#5604
This expands upon previous work done to better disconnect users from
SFTP when different events occur within Pterodactyl. This new logic also
accounts for password changes and their account being deleted entirely
from the system.
These events now trigger background jobs that will reach out to every
node they are associated with to ensure they're disconnected if
currently connected.
* Add throttling to resource creation endpoints
* Fix middleware registration for the throttlers
* Lock the server's resource models when adding new ones
* Throttle subusers even more
---------
Co-authored-by: DaneEveritt <dane@daneeveritt.com>