Jump to content




Recent Status Updates

  • Photo
      15 Nov
    duzamucha

    Hi, I am final year Interior Design Student from University of Huddersfield. I am currently working on my final major project which is going to be linked to coding. I was hoping that you could help me with my research. I have prepared a short survey, it would be a massive help if you could fill it in for me. It takes less than 2 minutes to complete, I promise. Here is the link: https://www.surveymonkey.com/s/73XLJKK Thank you so much in advance!

View All Updates

Developed by TechBiz Xccelerator
Photo
* * * * * 1 votes

Spring MVC security of submit

spring mvc security

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1 speculatius

speculatius

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 106 posts

Posted 30 January 2013 - 10:26 AM

Hi all,

currently I am learning spring mvc. Here is my situation...

Lets say I have model class like this:

class Person {
  private String firstname;
  private String surname;
  private Integer likesCount;
  // ...setters and getters
}

Then I have controller to enable user to change his name...

@Controller
class PersonUpdateController {
  @RequestMapping(value = "\person", method = RequestMethod.POST)
  public update(@ModelAttribute("person") Person person, Model model) {
    // ...validation and save
  }
}

And finally I have form...

<f:form action="person" method="post" modelAttribute="person">
  <f:input path="firstname"/>
  <f:input path="surname"/>
  <input type="submit"/>
</f:form>

When user uses this form, he is able to post only firstname and surname to the backend. But technically it is possible to send in request also likesCount, and that is security issue. In php framework Yii it is possible to specify which attributes should be propagated to backend by defining validation criteria on every model class. Is something like that possible in spring? I think some kind of interceptor could do the trick? Thank you.

#2 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2,577 posts

Posted 02 February 2013 - 02:07 PM

Add this somewhere in your controller

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.setDisallowedFields("likesCount");
}


#3 speculatius

speculatius

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 106 posts

Posted 03 February 2013 - 02:51 AM

Thanks. This looks like what I was looking for.






Powered by binpress