Forms: Use JWT for passing the Contact_Form object around#44360
Forms: Use JWT for passing the Contact_Form object around#44360
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
There was a problem hiding this comment.
Pull Request Overview
This PR implements JWT-based form submission to fix issues where forms placed in different templates don't get processed as expected. The implementation adds JWT encoding/decoding capabilities to the Contact_Form class while maintaining backward compatibility with the existing submission method.
- Adds JWT encoding/decoding methods to Contact_Form class for form instance reconstruction
- Includes a hidden JWT field in form HTML output for submission processing
- Updates form submission handler to prioritize JWT-based form reconstruction over the existing hash-based method
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| class-contact-form.php | Adds JWT encoding/decoding methods and includes JWT token in form output |
| class-contact-form-plugin.php | Updates submission handler to reconstruct forms from JWT token |
| Contact_Form_Test.php | Adds comprehensive test for JWT encoding/decoding functionality |
| composer.json | Adds jetpack-jwt package dependency |
| changelog files | Documents the changes for both plugin and package |
projects/packages/forms/changelog/update-add-jwt-form-encode-decode
Outdated
Show resolved
Hide resolved
projects/packages/forms/src/contact-form/class-contact-form.php
Outdated
Show resolved
Hide resolved
projects/packages/forms/src/contact-form/class-contact-form.php
Outdated
Show resolved
Hide resolved
projects/packages/forms/src/contact-form/class-contact-form.php
Outdated
Show resolved
Hide resolved
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 2 files.
|
Introduces JWT-based serialization and deserialization for contact form instances, enabling forms to be securely encoded and restored via a hidden JWT field. Updates include new methods in Contact_Form, changes to form rendering and processing, dependency on automattic/jetpack-jwt, and corresponding unit tests.
…ecode Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
a8757b2 to
63f849c
Compare
Introduces a has_verified_jwt property to the Contact_Form class to indicate JWT verification status. Updates form creation and submission logic to bypass certain ID checks when a verified JWT is present, improving security and flexibility for authenticated form submissions.
|
This might also resolve this issue? Forms with required fields were able to submit as empty when placed in templates. |
Seems like there's an issue with the interactivity API context picking up corrupt values (OB output?) |
CGastrell
left a comment
There was a problem hiding this comment.
All works perfectly! Tested on widgets and template parts, all smooth.
That said, I did push a phan update baseline to fix that check, but there are other checks not going through because some of the libs require php 8.3
Unsure what we should do with that
cc @Automattic/jetpack-monorepo for advice |
|
The composer lockfile was generated on PHP 8.3+, and the CI expects PHP 8.2 at the moment, so the fix is to run it with PHP 8.2, as done here: 1d87130 |
CGastrell
left a comment
There was a problem hiding this comment.
Works nicely! Let's ship this on Monday!
* Changelog and readme.txt edits. * Release packages that depend on status package * Revert "Forms: Use JWT for passing the Contact_Form object around (#44360)" (#44397) This reverts commit fa03729. * Release packages/forms 4.0.1 * Version bumps --------- Co-authored-by: Enej Bajgoric <enej.bajgoric@automattic.com>
This PR fixes the an issue where forms that are placed inside form different templates and don't get processed as expected.
Fixes FORMS-109
In future PRs we want to remove the non JWT token way of sumitting the form. But we are keeping it still this way so that we don't cause any mid deploy failures.
Proposed changes:
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
No
Testing instructions:
Add a form. Does it submit as expected?
Add a form in a widget. Does it submit as expected?