問題:Spring的數據綁定autoGrowCollectionLimit不能正常工作
Spring的數據綁定允許您設置最大尺寸()的自動創建
List<>
例如至3項。繞過這個限制是很容易的,只需通過修改發送給服務器的HTTP內容,Spring就可以創建一個包含3000多個項目的列表。換句話說:在測試我的web應用程序,我能夠通過創建惡意的HTTP請求強制Spring的數據綁定創建一個列表<>由4000項,雖然我已經將限制設置爲3項。這可能很容易導致任何應用程序服務器上的內存不足異常。
問:
我失去了一些東西明顯如何預防春季從這樣或者更確切地說,它是要報春的bug跟蹤系統中的錯誤?
版使用:
彈簧工具套件-3.3.0.RELEASE,
d:\平方米\回購\有機\ springframework的\彈簧的web \ 3.2.4.RELEASE \彈簧幅-3.2.4.RELEASE.jar描述:
我需要多個HTML元素
<input />
綁定到單個List<String>
對象,像:<input type="text" name="phoneNumber[0]" /> ... <input type="text" name="phoneNumber[n]" />
Spring默認使用
org.springframework.beans.propertyeditors.CustomCollectionEditor
執行此類轉換。下面是一個簡單的代碼片段,其中介紹了上述問題。代碼:
- 支持bean:
public class ContactDataEntity { private List<String> phoneNumber; // getters and setters }
- 粘合劑在控制器:
@RequestMapping(value = VIEW_PAGE_1, method = RequestMethod.POST) public String xxx(HttpServletRequest request, Model model) { // set and bind ContactDataEntity contactData = new ContactDataEntity(); ServletRequestDataBinder binder = new ServletRequestDataBinder(contactData); binder.setAutoGrowCollectionLimit(3); // set limit to 3 items binder.bind(request); // test binding results List<String> numbers = contactData.getPhoneNumber(); if (numbers != null) { System.out.print("numbers SIZE: " + numbers.size() + ", DATA: "); for (String s : numbers) System.out.print(s + ", "); System.out.print("\n"); } // validate and return view name... }
結果正確的數據(< = 3名的項目,一切工作正常,我使用Firefox的活HTTP頭):
(對不起,圖片鏈接,但「至少需要10聲譽發表圖片」和‘你至少需要10聲譽後2個以上環節。’)
結果的項目太多(> 3項,一切工作正常,500內部服務器E發生了錯誤):
i.stack.imgur.com/MfWYy。JPG
簡單的一招(> 3項,沒有報告錯誤,對不起,我在 '覆蓋' 錯字):
i.stack.imgur.com/FNlXE.jpg
讓我們開拓以上:
i.stack.imgur.com/XPIhc.jpg
所以,我的問題再次:我是缺少明顯的東西如何預防春季從這樣或拉特呃它應該被報告給Spring的bug跟蹤器?
//編輯:
我報告說,它作爲一個bug:https://jira.springsource.org/browse/SPR-11472