首页 \ 问答 \ Spring MVC和Thymeleaf防止实体Id泄漏(Spring MVC and Thymeleaf Prevent Entity Id Leak)

Spring MVC和Thymeleaf防止实体Id泄漏(Spring MVC and Thymeleaf Prevent Entity Id Leak)

我有Demand实体。 我可以毫无问题地更新我的实体,但我认为我的approch有一些安全问题。

demandController

@RequestMapping(value = "/details/{id}", method = RequestMethod.POST)
public String updateDemand(@PathVariable("id") Long id, @Valid @ModelAttribute Demand demand, BindingResult result) {
    if (result.hasErrors()) {
        return "demandUpdateForm";

    } else {
        demand.setDemandId(id);
        demandService.updateDemand(demand);
        return "redirect:/demands";
    }
}

serviceImpl

@Override
public Demand updateDemand(Demand demand) {
    return demandRepository.save(demand);
}

形成

 <form id="vendorForm" th:action="@{/demands/details/__${demand.demandId}__}" th:object="${demand}" method="post" >

如你所见,我从行动中得到了DemandId 。 例如,我想更新第5个id的demand并获取更新表单。 然后我通过开发人员工具更改了demandId并单击“提交”。 如果我修改id例如2nd和表单更新我的第二个id demand不是原来的第5个。 我该如何防止这种情况发生。


I have Demand entity. I can update my entity without any problem but I think my approch have some security problem.

demandController

@RequestMapping(value = "/details/{id}", method = RequestMethod.POST)
public String updateDemand(@PathVariable("id") Long id, @Valid @ModelAttribute Demand demand, BindingResult result) {
    if (result.hasErrors()) {
        return "demandUpdateForm";

    } else {
        demand.setDemandId(id);
        demandService.updateDemand(demand);
        return "redirect:/demands";
    }
}

serviceImpl

@Override
public Demand updateDemand(Demand demand) {
    return demandRepository.save(demand);
}

form

 <form id="vendorForm" th:action="@{/demands/details/__${demand.demandId}__}" th:object="${demand}" method="post" >

As you see I get DemandId from action. For example I want to update 5th id's demand and get the update form. Then I changed demandId via developer tools and click submit. If I modify id for example 2nd and form update my 2nd id demand not original the 5th one. How can I prevent this situation.


原文:https://stackoverflow.com/questions/37533894
更新时间:2023-07-27 20:07

最满意答案

使用innerHTML而不是value

document.getElementById("demo").innerHTML = '';

Use innerHTML instead of value:

document.getElementById("demo").innerHTML = '';

相关问答

更多
  • 据我所知,来自http://angular-ui.github.io/bootstrap/的typeahead指令的代码(自从我写完之后我就知道了:-))你将无法只按配置做你在这里问的事。 您需要分叉并根据您的需求进行调整。 它应该非常简单。 如果您觉得应该在指令中更改任何内容以便更容易扩展,请随意打开GitHub问题。 As far as I know the code of the typeahead directive from http://angular-ui.github.io/bootstra ...
  • PDF没有
    元素,因此无法搜索它们。 虽然URL地址暗示您的示例文件是PDF,但如果查看其源代码,您可以看到它只是一个纯HTML文件。 PDF's don't have
    elements, so there's no way to search for them. Although the URL address implies your example file is a PDF, if you look at its source code, you can see that it' ...
  • 这是您缺少的方法,您只需要访问ui.content属性。 response: function( event, ui ) { //console.log(ui.content); ui.content.unshift({value:"Add new account", label:"Add new account"}); } 这是工作的例子。 $( function() { var availableTags = [ "ActionScript", ...
  • twitter API的第1版已被弃用, 正在删除 。 不确定如何错过twitter开发站点上的巨大警告;)这意味着像上面这样简单的代码将不再起作用 。 因此,您现在需要使用1.1 API进行经过身份验证的请求(OAuth),并且它就像在(使用PHP) file_get_contents(http://search.twitter.com/ ...)那样简单。 我在你的个人资料中看不到你使用的任何服务器端语言,但我写了一篇冗长的帖子解释了这个问题 (图片)以及如何使用php库来执行经过身份验证的请求。 Ve ...
  • 相关文章

    更多
  • Spring MVC 3 深入总结
  • Thymeleaf标准方言SpringStandard
  • Spring MVC与表单提交的问题
  • Spring MVC文件上传
  • Thymeleaf+SpringMVC5示例教程
  • Spring MVC 入门实例教程
  • Spring Boot CLI 基于Thymeleaf的示例
  • 请教关于spring mvc中使用json-lib-ext-spring返回json的问题
  • Spring MVC入门
  • spring3MVC +spring security3 关于扩展UserDetailsService 无法注入service的疑问.
  • 最新问答

    更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。