#4170·YOURLS

Login dies with "Unauthorized action or expired link" when a plugin calls yourls_is_valid_user() before the admin auth check (root cause of #3087)

Author: blocoderCreated Sep 23, 2026Updated Sep 23, 2026

Code of Conduct

Submission validity

  • This is not a personal support request, that should be posted on discussions community.
  • I checked current issues and this request isn't a duplicate of an existing issue, opened or closed.

Self troubleshooting

Version

1.10.6

Description

After submitting the login form, YOURLS shows "Unauthorized action or expired link" (HTTP 403). Going back and reloading the page shows the admin area: the user is actually logged in, the auth cookie was set.

This is the behaviour reported in #3087, which was closed without a root cause. I traced it down on 1.10.6.

The login form is processed twice in the same request when any plugin calls yourls_is_valid_user() before yourls_maybe_require_auth() runs in admin/index.php:

  1. A plugin calls yourls_is_valid_user() early, e.g. in a kses_allowed_protocols filter. That filter runs on plugins_loaded via yourls_kses_init() (functions-kses.php#L46).
  2. username and password are in $_REQUEST, so yourls_check_username_password() runs. The nonce is verified for user -1 (nobody logged in yet), which is correct. Then yourls_set_user() defines YOURLS_USER, the cookie is stored and a redirect header is sent.
  3. admin/index.php calls yourls_maybe_require_auth(), which calls yourls_is_valid_user() again. username and password are still in $_REQUEST, so yourls_check_username_password() runs a second time.
  4. yourls_verify_nonce('admin_login') now uses YOURLS_USER instead of -1 (functions-auth.php#L133-L136, #L804-L809). The nonce was created for -1, so the check fails and yourls_die() sends the 403.

Plugins known to trigger it:

  • YOURLS/custom-protocol (current master): calls yourls_is_valid_user() in its kses_allowed_protocols filter.
  • dgw/yourls-dont-track-admins 1.2: called it on plugins_loaded. Version 1.3 moved the call to redirect_shorturl, which fixed it there. This matches the observations in #3087.

Expected Behavior

Calling yourls_is_valid_user() more than once per request should be safe. Plugins do it, and the docs do not warn against it.

Two possible fixes in core, either would do:

  • Verify the login nonce explicitly for the anonymous user, since the login form is always rendered for -1: yourls_verify_nonce( 'admin_login', false, '-1' ); in yourls_check_username_password().
  • Or remember the result of yourls_is_valid_user() for the rest of the request and return it on later calls.

Steps to Reproduce

  1. Fresh YOURLS 1.10.6, private mode.
  2. Activate the plugin YOURLS/custom-protocol.
  3. Log out, open /admin/, submit valid credentials.
  4. Result: "Unauthorized action or expired link". Reload /admin/: logged in.

Deactivating the plugin, or changing its check to look at the auth cookie only (isset( $_COOKIE[ yourls_cookie_name() ] ) && yourls_check_auth_cookie()), makes the login work again.

Context

Seen on a shared host (all-inkl), PHP 8.x, locale de_DE. After changing the check in custom-protocol as described above, the login works again.