Skip to content

Fix 500 in admin password-reset when profile is empty#32

Closed
redscar wants to merge 1 commit into
mainfrom
fix/password-reset-profile-sanitize-callback
Closed

Fix 500 in admin password-reset when profile is empty#32
redscar wants to merge 1 commit into
mainfrom
fix/password-reset-profile-sanitize-callback

Conversation

@redscar

@redscar redscar commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

The admin password-reset endpoint 500s whenever the profile param sanitizes to an empty string — which is the common case, since the UI posts profile: "". This wraps the sanitizer so it stops handing back the request object.

What changed

  • RestApi.php: wrapped the profile arg's sanitize_callback in a closure so only the value reaches sanitize_title.

Why

WordPress calls sanitize callbacks as call_user_func( $cb, $value, $request, $key ). Registering sanitize_title bare means the request object lands in its $fallback_title parameter — and sanitize_title returns that fallback whenever the input sanitizes to empty. So an empty profile came back as a WP_REST_Request, and the (string) cast in send_reset() fataled with "Object of class WP_REST_Request could not be converted to string."

The closure drops the extra args, so $fallback_title keeps its real default of '' and an empty profile resolves to the default login profile as intended.

How to test

POST /workos/v1/admin/users/{id}/password-reset with {"profile":""} against a WorkOS-linked user. Before: 500. After: normal response (reset sent, or a clean error for unlinked users).

The `profile` REST arg registered `sanitize_title` directly as its
sanitize_callback. WordPress invokes sanitize callbacks as
`call_user_func( $cb, $value, $request, $key )`, so the request object
landed in sanitize_title's `$fallback_title` parameter. When the input
sanitizes to an empty string — as it does for the common `profile: ""`
payload — sanitize_title returns the fallback, handing back the
WP_REST_Request object. The subsequent `(string)` cast in send_reset()
then fataled with "Object of class WP_REST_Request could not be
converted to string", surfacing as a 500.

Wrap the sanitizer in a closure so only the value reaches sanitize_title.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@redscar redscar self-assigned this Jun 19, 2026
@redscar redscar requested review from bordoni and johnhooks June 22, 2026 17:44
redscar added a commit that referenced this pull request Jun 30, 2026
Add documentation, README/AGENTS, and changelog coverage for the
WorkOS-Users-page change-email action and the admin-direct
immediate-commit behavior, and bump to 1.0.8.

- change-email.md: new "Admin-direct vs. self-service" matrix; admin
  response shape and 409 on initiate; Users-page surface; admin_changed
  event; drop the removed admin_bypass setting; test count 13 -> 19.
- README.md / AGENTS.md: reflect the new surface, admin-direct path, and
  admin_changed event.
- CHANGELOG.md / readme.txt: 1.0.8 entries for the change-email work
  (#33) and the password-reset empty-profile 500 fix (#32).
- Remove the now-unused change_email_admin_bypass_verification option.
- Bump Version / Stable tag / package.json to 1.0.8.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@redscar

redscar commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

Closing, merged into #33

@redscar redscar closed this Jun 30, 2026
redscar added a commit that referenced this pull request Jun 30, 2026
PR #32 is folded into #33, so #33 is the PR of record for the
password-reset empty-profile fix in this release.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant