Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions Classes/SecondFactor/Controller/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@
use Sandstorm\BackendUserManagement\SecondFactor\Service\SecondFactorSessionStorageService;
use Sandstorm\BackendUserManagement\SecondFactor\Service\TOTPService;

/**
* @Flow\Scope("singleton")
*/
class ModuleController extends AbstractModuleController
{
/**
* Read-only actions. All others change state and are POST only: Flow skips the CSRF check for GET requests
* ({@see \Neos\Flow\Security\RequestPattern\CsrfProtection::matchRequest()}), and module actions are reachable by
* GET - via the last URI segment ({@see \Neos\Neos\Routing\BackendModuleRoutePartHandler}) or `moduleArguments[@action]`.
* Without this, a forged GET could e.g. register an attacker-known TOTP secret for the victim (createAction).
* Same class of issue as GHSA-944w-5hjq-x6vh, whose core fix does not cover third-party modules.
* @var string[]
*/
private const array SAFE_ACTIONS = ['index', 'new', 'newTotp', 'newWebAuthn'];

/**
* @var SecondFactorRepository
* @Flow\Inject
Expand Down Expand Up @@ -92,6 +99,17 @@ class ModuleController extends AbstractModuleController
*/
protected $passwordlessLoginEnabled = false;

protected function initializeAction(): void
{
parent::initializeAction();
if (!in_array($this->request->getControllerActionName(), self::SAFE_ACTIONS, true)
&& $this->request->getHttpRequest()->getMethod() !== 'POST'
) {
$this->response->setHttpHeader('Allow', 'POST');
$this->throwStatus(405);
}
}

/**
* used to list all second factors of the current user
*/
Expand Down
17 changes: 17 additions & 0 deletions Tests/E2E/features/default/backend-module.feature
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,20 @@ Feature: Backend module for two-factor authentication management with default se
And I navigate to the 2FA management page
And I remove the 2FA device with the name "Editor Test Device"
Then There should be no 2FA device with the name "Editor Test Device"

# CSRF (GHSA-944w-5hjq-x6vh): Flow skips the CSRF check for GET - a forged link must not change state
Scenario: A forged GET request cannot register a 2FA device
When I log in with username "editor" and password "password"
And I send a forged GET request that registers a TOTP 2FA device with name "Attacker Device"
Then the forged request should be rejected as "Method Not Allowed"
When I navigate to the 2FA management page
Then There should be 0 enrolled 2FA devices

Scenario: A forged GET request cannot remove a 2FA device
When I log in with username "admin" and password "password"
And I navigate to the 2FA management page
And I add a new TOTP 2FA device with name "Admin Test Device"
And I send a forged GET request that removes the 2FA device with the name "Admin Test Device"
Then the forged request should be rejected as "Method Not Allowed"
When I navigate to the 2FA management page
Then There should be a 2FA device with the name "Admin Test Device"
7 changes: 7 additions & 0 deletions Tests/E2E/features/user-management/module.feature
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ Feature: User management backend module
And I open the user "jane" in the user management module
And I click "send-reset-mail" in the user details
Then "jane@example.com" should receive 1 mail

# CSRF (GHSA-944w-5hjq-x6vh): Flow skips the CSRF check for GET - a forged link must not change state
Scenario: A forged GET request cannot delete a user
When I log in with username "admin" and password "password"
And I send a forged GET request that deletes the user "jane" in the user management module
Then the forged request should be rejected as "Method Not Allowed"
And the user list should contain "jane"
173 changes: 78 additions & 95 deletions Tests/E2E/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Tests/E2E/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"test:neos9:username-is-email": "npm run generate-tests && SUT=neos9 FLOW_CONTEXT=Production/E2E-SUT/UserManagement/UsernameIsEmail npx playwright test --grep @username-is-email"
},
"devDependencies": {
"@types/node": "^25.5.0",
"@types/node": "^25.9.9",
"playwright-bdd": "^9.2.1",
"prettier": "^3.8.4",
"typescript": "^6.0.2"
"prettier": "^3.10.1",
"typescript": "^6.0.3"
},
"dependencies": {
"@playwright/test": "^1.58.2",
"otplib": "^13.4.0"
"@playwright/test": "^1.65.1",
"otplib": "^13.6.0"
}
}
Loading