开发者

Grails way to prevent bad request "ids" on url

开发者 https://www.devze.com 2022-12-16 22:58 出处:网络
Like here in stackoverflow if i force put bad characters on URL in id place it redirects you to a page error. I would like to know if with Grails it has some kind of plugin for prevent id like: \"123$

Like here in stackoverflow if i force put bad characters on URL in id place it redirects you to a page error. I would like to know if with Grails it has some kind of plugin for prevent id like: "123$#3" or an easy way because i have a lot of actions and do something like below dont seems to be the best way:


def find = {   

     def val = OwnStringUtilsClass.verify(params.id)
     val ? Book.get(val) : response.sendErr开发者_StackOverflow社区or(404)
}


You can use the following in grails-app/conf/UrlMappings.groovy:

  "/$controller/$action?/$id?"{
          constraints {
                    id(matches:/\d*/)
              }
      }

This will ensure that the id is numeric.


You could try using a controller filter.

0

精彩评论

暂无评论...
验证码 换一张
取 消