Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Tighten routing rule for userforms ping action #1224

Conversation

tiller1010
Copy link
Contributor

… UserDefinedForm

Closes #1223

Summary

  • Checks for "Fields" method
  • Check if the dataRecord is an instance of UserDefinedForm. If not, return 404.

@GuySartorelli
Copy link
Member

Can you please describe the perceived problem this change is intended to solve? I can't think of a scenario where this would be necessary?

@tiller1010
Copy link
Contributor Author

tiller1010 commented Jul 14, 2023

@GuySartorelli This is to prevent emergencies from visiting "/UserDefinedFormController"
This only occurs from the root url, visiting "/any-page-url/UserDefinedFormController" returns a 404 instead:

image

Versus

image

@michalkleiner
Copy link
Contributor

It probably shouldn't error on any level of the structure, but why do you need to visit the URL of the controller? Does it happen when you submit a form that you made to be your homepage?

@GuySartorelli
Copy link
Member

After a quick play around, this happens even without any userform on the home page. There's a route in _config/routes.yml that is defined as such:

SilverStripe\Control\Director:
  rules:
    UserDefinedFormController//$Action: SilverStripe\UserForms\Control\UserDefinedFormController

So, first step would be to find out what this route is even doing there in the first place.
Second step would be to see if there's a way to do that without needing a global route, which just feels wrong.
If that's not possible, then an approach like the one in this PR could be considered, but it feels like we're hitting a nail with a screwdriver here.

@NightJar
Copy link
Contributor

NightJar commented Jul 19, 2023

The premise of this PR is that a UserDefinedController is being loaded as the controller for a page that does not have a UserForm on it.

The editor extension is missing. Simple as that.

@tiller1010 I would suggest checking your HomePage::$controller_name config (I'm making assumption on naming here, but hopefully you get the idea).

So, first step would be to find out what this route is even doing there in the first place.

@GuySartorelli
The UserDefinedFormController route is to allow for ping actions, in order that someone doing a bazillion field form over 5 "pages" (javascript show/hide events) doesn't have the security token time out on them. The same as the CMS does.

The confusion stems from the route being for a Page type controller, where no page is defined because it's a direct route. However the route URL controller defines "The page for / is [...::class]", so the ContentController subclass can happily load a data model for itself (this is an assumption - I've not checked... that or it's using a placebo "null record" - thus SiteTree, not HomePage or whatever). This is perhaps incorrect behaviour, but is not the root cause of this issue. The controller is not designed to be called directly.

If any commit should result from this error, I would guess that the route should probably more accurately be:

SilverStripe\Control\Director:
  rules:
    UserDefinedFormController/ping:
      Controller: SilverStripe\UserForms\Control\UserDefinedFormController
      Action: ping

I missed at the beginning of my reply that the controller is being called directly, with no action. What is the reason for this? I don't think it should happen. The second part of my reply deals more directly to that point.

@tiller1010 tiller1010 requested a review from NightJar July 19, 2023 15:38
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

Of all of these changes, only the one in routes.yml seems necessary - that on its own resolves the issue.

code/Control/UserDefinedFormController.php Outdated Show resolved Hide resolved
code/Form/UserForm.php Outdated Show resolved Hide resolved
code/Form/UserForm.php Outdated Show resolved Hide resolved
@GuySartorelli GuySartorelli changed the base branch from 5 to 5.15 August 3, 2023 23:06
@GuySartorelli
Copy link
Member

I've also changed the target branch to 5.15. Please reset the commits so that this PR has only one commit in it, which is the change being made to routes.yml.

@GuySartorelli GuySartorelli force-pushed the hotfix/5.15.4/check-for-methods-and-class branch 3 times, most recently from 648f308 to 00a25dc Compare August 16, 2023 23:54
@GuySartorelli GuySartorelli force-pushed the hotfix/5.15.4/check-for-methods-and-class branch from 00a25dc to 237ad41 Compare August 16, 2023 23:55
@GuySartorelli
Copy link
Member

I've reset the commits and made the requested changes. Someone else will need to review this now, though.

@GuySartorelli GuySartorelli dismissed their stale review August 16, 2023 23:55

I've made these changes

Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

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

Tested locally, I can still create and submit userforms

Had a look around, seems reasonable to limit this to just ping

ping is used here - https://github.com/silverstripe/silverstripe-userforms/blob/6/client/src/bundles/UserForms.js#L757

@emteknetnz emteknetnz merged commit cf9a109 into silverstripe:5.15 Aug 17, 2023
12 checks passed
@GuySartorelli GuySartorelli changed the title fix: added checks for methods and redirect if the controller is not a… FIX Tighten routing rule for userforms ping action Aug 18, 2023
@tiller1010 tiller1010 deleted the hotfix/5.15.4/check-for-methods-and-class branch November 6, 2023 14:08
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.

5 participants