Restrict Gravity Forms REST routes to authenticated users - #2049
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Hardens the Gravity Forms REST API integration by enforcing authenticated access and preventing sensitive form configuration leakage via REST responses.
Changes:
- Restricts
/godam/v1/gformsresponses to an explicit allowlist (id,title,description) viaresolve_requested_fields. - Requires
upload_filescapability for Gravity Forms REST endpoints (matching Video Editor permissions). - Adds unit tests + minimal WordPress REST controller stub and updates Video Editor API client to send
X-WP-Nonce.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
inc/classes/rest-api/class-gf.php |
Adds allowlist enforcement and permission checks for Gravity Forms REST routes. |
pages/video-editor/redux/api/gravity-forms.js |
Sends REST nonce header so authenticated requests pass the new capability gate. |
tests/php/GravityFormsFieldAllowlistTest.php |
Adds unit coverage for the allowlist field resolution logic. |
tests/stubs/class-wp-rest-controller.php |
Provides a minimal WP REST controller stub for pure unit tests. |
tests/bootstrap.php |
Bootstraps the new stub and loads REST base/GF classes for unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…routes GET /godam/v1/gforms was registered with __return_true and returned GFAPI::get_forms() verbatim. The response was narrowed only when the caller passed a `fields` parameter, so an unauthenticated request that omitted it received the complete form configuration: notification recipients and routing, confirmation URLs, the full field structure, and any settings an add-on had persisted into form meta — including credentials. - Gate /gforms and /gform on current_user_can( 'upload_files' ), matching the capability the Video Editor page itself registers with. - Narrow the collection to id, title and description on the server, unconditionally, so an omitted or unrecognised `fields` value can no longer widen the response. - Send X-WP-Nonce from the Video Editor's Gravity Forms slice. Without it a cookie-authenticated request is evaluated as anonymous and the form picker breaks under the new capability check. Adds unit cover for the allowlist. Authorisation itself needs the wp-phpunit harness the bootstrap notes as a follow-up. Refs rtCamp/godam-core#1289
- Fall back to the allowlist when a `fields` selection names nothing allowed. It previously resolved to an empty set, so the endpoint returned a list of empty objects. Falling back narrows to the same three fields, so it cannot widen the response. - Collapse duplicates in the requested list, so `fields=id,id,title` no longer yields a repeated entry. - Only send X-WP-Nonce when a nonce is actually available, rather than setting an empty header. Refs rtCamp/godam-core#1289
8dcd608 to
19d111f
Compare
|
Tested locally against Summary
Testing logsUnit tests —
|
This pull request addresses a security issue in the Gravity Forms REST API integration by restricting which form fields can be exposed, tightening permissions, and adding comprehensive unit tests to prevent regression. It also updates the frontend to send authentication headers and improves test bootstrapping for isolated environments.
Security and Permissions:
id,title, anddescriptionfields are now allowed in Gravity Forms REST API responses, preventing accidental disclosure of sensitive form data such as notifications, confirmations, or add-on settings. (inc/classes/rest-api/class-gf.php) [1] [2]upload_filescapability, matching the Video Editor page's permission requirements. (inc/classes/rest-api/class-gf.php) [1] [2]Backend Logic and Tests:
resolve_requested_fieldsmethod to strictly enforce the allowlist, regardless of thefieldsparameter in the request. (inc/classes/rest-api/class-gf.php)tests/php/GravityFormsFieldAllowlistTest.php)WP_REST_Controllerto allow unit tests to run without a full WordPress environment. (tests/stubs/class-wp-rest-controller.php,tests/bootstrap.php) [1] [2]Frontend Integration:
pages/video-editor/redux/api/gravity-forms.js)…routesGET /godam/v1/gforms was registered with __return_true and returned GFAPI::get_forms() verbatim. The response was narrowed only when the caller passed a
fieldsparameter, so an unauthenticated request that omitted it received the complete form configuration: notification recipients and routing, confirmation URLs, the full field structure, and any settings an add-on had persisted into form meta — including credentials.fieldsvalue can no longer widen the response.Adds unit cover for the allowlist. Authorisation itself needs the wp-phpunit harness the bootstrap notes as a follow-up.
Refs rtCamp/godam-core#1289