Skip to content

Restrict the Media Editor's form routes to users who can open it - #2252

Merged
subodhr258 merged 2 commits into
mainfrom
fix/form-routes-editor-only
Oct 26, 2026
Merged

subodhr258 merged 2 commits into
mainfrom
fix/form-routes-editor-only

Conversation

@subodhr258

Copy link
Copy Markdown
Collaborator

What changes

Form routes used only by the Media Editor now need upload_files, the capability the Media Editor page requires and the Gravity Forms routes already use (#2049). The shared check is Base::forms_permissions_check() in inc/classes/rest-api/class-base.php; class-gf.php now inherits it, with no change in behaviour.

Routes Change
WPForms, SureForms, Forminator, Fluent Forms, Ninja Forms, Everest Forms: listing and single form need upload_files
Contact Form 7 single form, Jetpack single form (jetpack-form) need upload_files
Listings return what the pickers use: id and title (Forminator: id and name, which its picker shows)

Jetpack forms inside videos (inc/classes/rest-api/class-jetpack.php, new is_host_post_public()): the player shows a Jetpack form, and the submit route accepts an entry for it, only when the post holding the form is published, viewable and has no password. Otherwise the submit route answers 404 form_not_found, as for a missing post. The submit route itself stays public, because the player posts to it. The Media Editor's Jetpack preview shows a non-public post's form only to a user who can edit that post.

No change: the MetForm routes and the Jetpack forms listing stay public. They return only what WordPress already shows visitors: MetForm forms are public posts, and the Jetpack listing has the titles of published posts.

Testing

Throwaway WordPress (Playground) with the 2.5.0 release plus these files; Jetpack (contact forms on), WPForms Lite, SureForms, Fluent Forms, Ninja Forms, Everest Forms, Forminator, MetForm and Contact Form 7 installed.

Check Result
Logged-out request to any gated listing or single-form route 401
Subscriber, Contributor 403
Author, Admin 200, same form HTML as before
Media Editor as an Author (built 2.5.0 scripts): every form plugin's picker and preview loads; pickers show form titles
Jetpack form in a video on a published post: shown, submitted through the player script entry saved, notification sent, as before
Jetpack form whose post is a draft, private, pending, scheduled, password-protected or trashed not shown on the front end; a submission gets 404 and creates no entry or mail
Jetpack preview of another author's draft post 404 for that Author; their own draft shows
  • PHPUnit: 46 new tests (FormRoutePermissionTest, FormListingFieldsTest, JetpackFormHostPostTest); full suite OK (659 tests).
  • phpcs clean; bin/hook-check checks pass. No JS changed.

Worth knowing

  • Anything outside the Media Editor that called these routes without signing in now gets 401.
  • Listings no longer include description, content, client_id or status.
  • A Jetpack form layer whose post is not public, or has a password, no longer shows on the front end. The Media Editor's picker still lists password-protected posts.
  • Found while testing, not changed here (they behave the same before and after):
    • With Jetpack 16.3.1, the player's Jetpack form submission fails validation, because Jetpack added a hidden jetpack_form_fill_duration field that jetpack-form.js doesn't skip. It works with Jetpack 15.4.1.
    • The Contact Form 7 single-form route answers contactform7_not_active on current Contact Form 7 (6.2.3), because it checks for a class CF7 no longer has.
    • The Jetpack submit route always loads the first Jetpack form in the post.

QA:

  1. As an Author, open the Media Editor and add a form layer for each installed form plugin: the pickers list forms and the previews render.
  2. On a published post, play a video with a Jetpack form layer and submit the form: the entry is saved.
  3. Logged out, open /wp-json/godam/v1/wpforms: refused.

Issue: rtCamp/godam-plugin-wp#73

@subodhr258 subodhr258 self-assigned this Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
13 0 13

⚠️ Warnings (13)

📁 readme.txt (2 warnings)
📍 Line 🔖 Check 💬 Message
0 mismatched_plugin_name Plugin name "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" is different from the name declared in plugin header "GoDAM".
0 trademarked_term The plugin name includes a restricted term. Your chosen plugin name - "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" - contains the restricted term "wordpress" which cannot be used at all in your plugin name.
📁 assets/build/css/main.css (1 warning)
📍 Line 🔖 Check 💬 Message
0 EnqueuedStylesScope This style is being loaded in all contexts.
📁 assets/src/libs/analytics.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/10/26/hello-world/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
📁 assets/build/js/main.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/10/26/hello-world/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

The form listing and single-form routes are only called by the Media
Editor, so they now need upload_files, the capability the Media Editor
page requires and the Gravity Forms routes already use. The shared check
moves into the REST base class. The listings return what the form pickers
use: a form's id and title (Forminator: name).

The player shows a Jetpack form, and accepts entries for it, only when
the post that holds the form is published, viewable and has no password.
The Media Editor's Jetpack preview skips a post its user can neither see
nor edit. The Jetpack form submission route stays public, since the
player posts to it.

The MetForm routes and the Jetpack forms listing stay public: they return
only what WordPress already shows visitors (public form posts and the
titles of published posts).
@subodhr258
subodhr258 force-pushed the fix/form-routes-editor-only branch from 53f6e50 to a23fd84 Compare October 23, 2026 06:21
@subodhr258
subodhr258 changed the base branch from develop to main October 23, 2026 06:21
@subodhr258

Copy link
Copy Markdown
Collaborator Author

Tested together with the other five 2.5.1 PRs on a hosted test site connected to production GoDAM Central. Full table and all recordings: https://github.com/rtCamp/godam-plugin-wp/issues/68 (recordings are in the rtCamp Test media library; sign in to watch).

Tested commit 53f6e5006; the current head a23fd84e5 has the same code.

  • WPForms, SureForms and Everest Forms lists: signed-in admin 200, logged-out visitor 401: T9. On 2.5.0 the visitor got 200 on all three.

@elifvish elifvish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Low: the Jetpack picker (get_jetpack_forms(), outside this diff) still lists forms from published posts that have a password, but is_host_post_public() now hides those forms on the front end and refuses their submissions, so an author can pick a form that never shows. Adding AND p.post_password = '' to that query would line the picker up with the front end.

Verification

  • Head tested: a23fd84e5a. PHPUnit on this PR's head: 659/659 OK.
  • All seven 2.5.1 PRs merged onto main (no conflicts): PHPUnit 915/915, Jest 690/690, build:prod OK.
  • Playwright API checks against that build on a local WordPress 7.1.3 site: 13/13 for this PR.
  • Not covered: Jetpack (not installed on test-this): render/submit gating covered by unit tests only; Subscriber role: holds upload_files on test-this, so not checked there; SureForms, Forminator, Everest, CF7 (not installed).

Screenshots and a recording of the local run are available on request.

@KMchaudhary

Copy link
Copy Markdown
Collaborator

Review — Approvable ✅

Reviewed at high effort as an authorization hotfix. This is a clean, deep fix.

Authorization (the core change)

  • Every Media-Editor-only form route (gforms/gform, wpforms/wpform, sureforms/sureform, forminator-forms/-form, fluent-forms/-form, ninja-forms/-form, everest-forms/-form, cf7-form, jetpack-form) correctly moves from __return_true to forms_permissions_check() → upload_files, the capability the Media Editor page itself requires.
  • The three routes intentionally left public (jetpack-form-submit, metforms/metform, jetpack-forms) are the right ones — the player posts to the submit route, and the others only repeat data WordPress already shows visitors.
  • test_every_route_is_classified is a nice touch: a new form route can't ship without being deliberately placed in the editor-only or public list.

Jetpack host-post visibility

  • is_host_post_public() (is_post_publicly_viewable() + no password) is applied consistently to the preview route, the static renderer, and — verified end-to-end — the public submit path via load_form_into_memory_with_origin(). A submission for a form in a draft/private/pending/scheduled/trashed/password-protected post is refused with form_not_found and stores nothing, even though the submit route stays public. Attacker-controlled origin-post-id/contact-form-id can only target a public post.
  • The Media Editor preview still shows a non-public post's form only to a user who can edit_post it. Correct.

Also good: forms_permissions_check consolidated into Base (GF inherits, identical behaviour); listings trimmed to just the id + title/name the pickers use, dropping description/content/client_id/status; 46 new tests across permissions, listing fields, and host-post visibility.

Note (no change needed): is_post_publicly_viewable() requires WP 5.7+; plugin min is 6.5, so fine.

The pre-existing CF7 6.2.3 and Jetpack 16.3.1 observations in the description are not introduced by this PR and are out of scope for the hotfix.

LGTM. 🚀

@subodhr258
subodhr258 merged commit 068a6a7 into main Oct 26, 2026
9 of 10 checks passed
@subodhr258
subodhr258 deleted the fix/form-routes-editor-only branch October 26, 2026 07:15
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.

3 participants