Skip to content

Consistently unslash superglobals before use - #100

Open
miyanialkesh7 wants to merge 1 commit into
HandyPlugins:developfrom
miyanialkesh7:fix/security-input-sanitization-hardening
Open

Consistently unslash superglobals before use#100
miyanialkesh7 wants to merge 1 commit into
HandyPlugins:developfrom
miyanialkesh7:fix/security-input-sanitization-hardening

Conversation

@miyanialkesh7

@miyanialkesh7 miyanialkesh7 commented Aug 15, 2026

Copy link
Copy Markdown

Summary

  • Adds wp_unslash() before sanitizing/using $_GET/$_POST/$_REQUEST values in 7 spots (redirect_to handling in LoginManager, CodeLogin, shortcode; the magic-link token; the settings token_interval switch).
  • Output was already escaped downstream in nearly all cases, so this is defense-in-depth hardening for consistency with the rest of the codebase, not a fix for a known-exploitable bug.
  • The magic-link token itself is left unsanitized after wp_unslash() — it's an opaque value that's hashed and compared exactly, so sanitize_text_field() adds no security and risked mangling tokens customized via the magic_login_create_user_token filter.

Why

Found during a security audit pass: these call sites were the only ones in the codebase reading superglobals without wp_unslash() first.

Test Plan

  • php -l on all changed files — no syntax errors
  • vendor/bin/phpcs --standard=phpcs.xml on changed files — 0 errors/warnings
  • vendor/bin/phpunit — 8/8 passing
  • Activated plugin on a local WP 7.0.4 site — no fatals/warnings in the error log
  • wp-login.php?redirect_to=... renders the hidden field correctly (unslashed + escaped)
  • Settings-save token_interval switch verified behavior-preserving for normal values and correctly strips magic-quote-style slashing on malformed input

Comment thread includes/classes/LoginManager.php Outdated
// Use a generic error message to ensure user ids can't be sniffed
$user_id = (int) $_GET['user_id']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
$token = $_GET['token']; //phpcs:ignore
$token = sanitize_text_field( wp_unslash( $_GET['token'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid passing the magic-login token through sanitize_text_field(). The token is an opaque value that is hashed and compared exactly. Sanitizing it provides no additional security in this code path and may modify tokens customized through the magic_login_create_user_token filter. wp_unslash( $_GET['token'] ) should be sufficient here.

Comment thread readme.txt Outdated
== Changelog ==

= 2.8.2 (Aug 15, 2026) =
* [Improved] Consistently unslash $_GET/$_POST/$_REQUEST values (redirect_to, login token, token interval) before sanitizing/using them, for defense-in-depth.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the version bump and changelog entry from this PR. Release metadata will be handled separately so it can be coordinated with other pending changes.

Just add changelog items as comment.

$_GET/$_POST/$_REQUEST reads for the login redirect target, the magic-link
token, and the settings token interval were used without wp_unslash()
first in a few spots. Output was already escaped downstream in most cases,
so this is defense-in-depth hardening rather than a fix for an exploitable
issue, and brings these call sites in line with the wp_unslash() +
sanitize pattern already used everywhere else in the codebase.

The magic-link token itself is left unsanitized after wp_unslash(): it's
an opaque value that's hashed and compared exactly, so sanitize_text_field()
adds no security and risked mangling tokens customized via the
magic_login_create_user_token filter.
@miyanialkesh7
miyanialkesh7 force-pushed the fix/security-input-sanitization-hardening branch from fced613 to ce09b5c Compare August 25, 2026 06:12
@miyanialkesh7

Copy link
Copy Markdown
Author

@mustafauysal Addressed both review comments:

  1. Token sanitization — removed sanitize_text_field() from the login token in LoginManager.php; it's now just wp_unslash( $_GET['token'] ), matching your point that the token is opaque, hashed, and compared exactly, so sanitizing it added no security and could have mangled tokens customized via magic_login_create_user_token. Narrowed the phpcs ignore comment on that line to the two specific sniffs it now needs (NonceVerification.Recommended, ValidatedSanitizedInput.InputNotSanitized) instead of relying on the sanitize call to satisfy phpcs.
  2. Version bump / changelog — removed from the PR (force-pushed the amended commit). Changelog items for this change, for whenever release notes are prepared:
  • [Improved] Consistently unslash $_GET/$_POST/$_REQUEST values (redirect_to, login token, token interval) before use, for defense-in-depth.

Re-ran phpcs (0 errors/warnings) and phpunit (8/8 passing) after the changes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants