MVC5 BindAttribute
// POST: Movies/Create
// 為了防止“過多發布”攻擊,請啟用要綁定到的特定屬性,有關
// 詳細信息,請參閱 http://go.microsoft.com/fwlink/?LinkId=317598。
[HttpPost]
[ValidateAntiForgeryToken]
publicActionResultCreate([Bind(Include="ID,Title,ReleaseDate,Genre,Price")]Movie movie)
{
if(ModelState.IsValid)
{
db.Movies.Add(movie);
db.SaveChanges();
returnRedirectToAction("Index");
}
returnView(movie);
}
其中[Bind(Include="ID,Title,ReleaseDate,Genre,Price")]
The Bind attribute is another important security mechanism that keeps hackers from over-posting data to your model.
大意是:BindAttribute 是一個防止黑客“OverPost”攻擊的重要安全機制。
"OverPost": 其實就是使用表單提交工具模擬提交時,手動加一些奇怪的東西。Form Post時,RequestBody是ID=1&Title=123&ReleaseDate=20150502&Genre=Science&Price=10&HHH=test。“HHH=test”就是“over-posting”了。詳細可查看: Over Posting Note