Skip to content

RestfulController should support updates via POST in addition to PUT or allow additional configuration. #9926

Closed

Description

@codeconsole

AngularJS by default uses POST requests to .$save objects. It does not use PUT requests.

If you create a User object and a scaffolded UserController, then create a resources URLMapping. There is no way to allow allow POST updates.

A working simple Grails 3.1.6 example is here:
https://github.com/codeconsole/grails3bugs

Simply clone that github app, run, and click the Demonstrate Bug button on the index page.

Fix should be to default RestfulController to

static allowedMethods = [save: "POST", update: ["POST", "PUT"], delete: "DELETE"]

or allow overriding.

According to burt [9:01 PM]
I looked at this in a debugger and it's hard to tell because it's mostly generated code, but the controller ends up being a subclass of RestfulController and there's code generated by an AST that does the check for allowed methods and that's where the 405 status is being set. it looks to me like it's ignoring the allowedMethods map defined in the controller and using the one from the RestfulController base class with the standard values

Activity

  1. jeffscottbrown commented on May 11, 2016

    @jeffscottbrown
    Contributor

    it looks to me like it's ignoring the allowedMethods map defined in the controller and using the one from the RestfulController base class with the standard values

    That is correct. At present the code that deals with allowedMethods restrictions is added directly the controller action methods at compile time so when RestfulController is compiled, the allowedMethods property in that class are what is used. That could be modified to support a subclass' allowedMethods, but that is not what currently happens.

  2. codeconsole commented on May 12, 2016

    @codeconsole
    ContributorAuthor

    So you would classify this as a bug, no? Maybe at the very least we can open up POSTs to updates. I don't really see a security problem with this, do you?

  3. codeconsole commented on May 12, 2016

    @codeconsole
    ContributorAuthor

    The more I think about it, wouldn't it be better if RestfulController didn't even have static allowedMethods? What is the point of it having it anyhow? Just because someone want's to expose rest services on their controller, doesn't mean it should be locked down from a security stand point.

  4. added a commit that references this issue on May 12, 2016
  5. added a commit that references this issue on May 26, 2016
  6. jeffscottbrown commented on May 26, 2016

    @jeffscottbrown
    Contributor

    The more I think about it, wouldn't it be better if RestfulController didn't even have static allowedMethods?

    I don't agree. I think RestfulController should have sensible restrictions in it, and you should be allowed to override those.

  7. added this to the grails-3.2.0.M2 milestone on Jul 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions