Skip to content

Users: API token replaced by a simple GET request (no CSRF token) #115

Open

Description

@njoubert-cleverage

Description

The "generateToken" action of the users (edit page) replaces the API token of a user on a simple GET request (/process/user/{id}/generate-token, route methods GET|POST), without CSRF token nor confirmation. An admin following a forged link (image, link in an email…) unknowingly replaces the token of a user: the previous token stops working (HTTP integrations broken). The new token is only displayed to the admin (flash message), so there is no token leak: the impact is a denial of service of the integrations.

The token is also generated with md5(uniqid(date('YmdHis'))), which is predictable (based on the time).

Reproduction

  1. Logged in as an admin, GET /process/user/<id>/generate-token
  2. The token of the user is replaced (302 to the edit page, new token in the flash message)

Expected: the token is only replaced by a POST request with a valid CSRF token, after confirmation.

Tested on main (e298007) in process-bundle-demo: PHP 8.5, Symfony 7.4, EasyAdmin 5.

Cause

UserCrudController: linkToCrudAction('generateToken') (link), #[AdminRoute] without methods, no CSRF check.

Proposed fix

  • action rendered as a POST form (renderAsForm()) with a confirmation, URL with a CSRF token per user
  • route restricted to POST, CSRF token checked (403 otherwise)
  • token generated with random_bytes()

Requirements

  • Documentation updates
    • Reference
    • Changelog
  • Unit tests

Breaking changes

The direct GET /process/user/{id}/generate-token URL no longer works (405): the token is generated from the button of the user edit page. Upgrade note in UPGRADE.md v4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions