Updated all existing authenticated form POSTs to use (and validate) an anti forgery token

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4044471
This commit is contained in:
skewed
2009-12-22 23:32:37 +00:00
parent 35558ee5d5
commit bbab6d0ce5
22 changed files with 22 additions and 27 deletions

View File

@@ -1,7 +1,7 @@
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Orchard.Core.Settings.ViewModels.SettingsIndexViewModel>" %>
<%@ Import Namespace="Orchard.Mvc.Html" %>
<h2>Edit Settings</h2>
<%using (Html.BeginForm()) { %>
<h2><%=Html.TitleForPage("Edit Settings")%></h2>
<%using (Html.BeginFormAntiForgeryPost()) { %>
<%= Html.ValidationSummary() %>
<fieldset>
<legend>Global Settings</legend>

View File

@@ -5,7 +5,7 @@
<%@ Import Namespace="Orchard.Mvc.Html" %>
<h2>Delete pages</h2>
<p>Are you sure you want to delete the pages?</p>
<% using (Html.BeginForm()) { %>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%= Html.ValidationSummary() %>
<fieldset>
<input type="hidden" name="<%=Html.NameOf(m => m.Options.BulkAction)%>" value="<%=PageIndexBulkAction.Delete%>" />

View File

@@ -3,7 +3,7 @@
<%@ Import Namespace="Orchard.Utility"%>
<%@ Import Namespace="Orchard.CmsPages.Services.Templates"%>
<%@ Import Namespace="Orchard.Mvc.Html" %>
<% using (Html.BeginForm()) { %>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<h2>Publish later</h2>
<p>Enter the scheduled publication date:</p>
<%=Html.ValidationSummary() %>

View File

@@ -3,7 +3,7 @@
<%@ Import Namespace="Orchard.Mvc.Html" %>
<h2>Change Template</h2>
<p>Select your layout from one of the templates below.</p>
<% using (Html.BeginForm()) {
<% using (Html.BeginFormAntiForgeryPost()) {
%><%= Html.ValidationSummary() %>
<ul class="templates"><%
foreach (var template in Model.Templates) {

View File

@@ -2,7 +2,7 @@
<%@ Import Namespace="Orchard.Mvc.Html" %>
<h2>Add a Page</h2>
<p>Select your layout from one of the templates below.</p>
<% using (Html.BeginForm()) { %>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.ValidationSummary() %>
<%=Html.EditorForModel() %>
<% } %>

View File

@@ -5,7 +5,7 @@
<p class="bottomSpacer"><%=_Encoded("about setting up a page") %></p>
<%=Html.ValidationSummary() %>
<div class="sections">
<% using (Html.BeginForm()) { %>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<div class="primary">
<h3><%=_Encoded("Page Content") %></h3>
<%-- todo: (heskew) change the editors to be self-contained (fieldset > editor) --%>

View File

@@ -5,7 +5,7 @@
<%-- todo: (heskew) localize --%>
<h2>Manage Pages</h2>
<p>Possible text about setting up a page goes here. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla erat turpis, blandit eget feugiat nec, tempus vel quam. Mauris et neque eget justo suscipit blandit.</p>
<% using (Html.BeginForm()) { %>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.ValidationSummary() %>
<fieldset class="actions bulk">
<label for="publishActions">Actions: </label>

View File

@@ -10,7 +10,7 @@
new {name = navigation.FolderName, mediaPath = navigation.FolderPath})%> &#62;
<% } %>
Add a Folder</p>
<%using (Html.BeginForm()) { %>
<%using (Html.BeginFormAntiForgeryPost()) { %>
<%= Html.ValidationSummary() %>
<fieldset>
<label for="Name">Folder Name:</label>

View File

@@ -13,7 +13,7 @@
<% } %>
Edit Media </p>
<div class="sections">
<%using (Html.BeginForm()) { %>
<%using (Html.BeginFormAntiForgeryPost()) { %>
<%= Html.ValidationSummary() %>
<div class="primary">
<h3>About this media</h3>

View File

@@ -11,7 +11,7 @@
<% } %>
Folder Properties</p>
<%using (Html.BeginForm()) { %>
<%using (Html.BeginFormAntiForgeryPost()) { %>
<%= Html.ValidationSummary() %>
<fieldset>
<label for="Name">Folder Name:</label>

View File

@@ -2,7 +2,7 @@
<%@ Import Namespace="Orchard.Roles.ViewModels"%>
<%@ Import Namespace="Orchard.Mvc.Html" %>
<h2>Add Role</h2>
<% using (Html.BeginForm()) { %>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.ValidationSummary()%>
<fieldset>
<legend>Information</legend>

View File

@@ -4,7 +4,7 @@
<%@ Import Namespace="Orchard.Mvc.Html" %>
<h3>
Create Page</h3>
<%using (Html.BeginForm()) { %>
<%using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.LabelFor(x => x.Name)%><%=Html.EditorFor(x => x.Name)%>
<input type="submit" name="submit" value="Create" />

View File

@@ -4,7 +4,7 @@
<%@ Import Namespace="Orchard.Mvc.Html" %>
<h3>
Edit Page</h3>
<%using (Html.BeginForm()) { %>
<%using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.EditorForItem(Model.Page) %>
<input type="submit" name="submit" value="Save" />
<%} %>

View File

@@ -3,7 +3,7 @@
<%@ Import Namespace="Orchard.Security" %>
<%@ Import Namespace="Orchard.Mvc.Html" %>
<h2>Add User</h2>
<%using (Html.BeginForm()) { %>
<%using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.ValidationSummary() %>
<%=Html.EditorFor(m=>m.UserName, "inputTextLarge") %>
<%=Html.EditorFor(m=>m.Email, "inputTextLarge") %>

View File

@@ -4,7 +4,7 @@
<%@ Import Namespace="Orchard.Mvc.Html" %>
<h2>
Edit User</h2>
<%using (Html.BeginForm()) { %>
<%using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.ValidationSummary() %>
<%=Html.EditorFor(m=>m.Id) %>
<%=Html.EditorFor(m=>m.UserName, "inputTextLarge") %>

View File

@@ -3,7 +3,7 @@
<%@ Import Namespace="Orchard.Security" %>
<%@ Import Namespace="Orchard.Mvc.Html" %>
<h2>Manage Users</h2>
<% using (Html.BeginForm()) { %>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.ValidationSummary()%>
<div class="manage"><%=Html.ActionLink("Add a new user", "Create", new { }, new { @class = "button" })%></div>
<fieldset>

View File

@@ -6,7 +6,7 @@
<p>New passwords are required to be a minimum of <%=Html.Encode(ViewData["PasswordLength"])%> characters in length.</p>
<%= Html.ValidationSummary("Password change was unsuccessful. Please correct the errors and try again.")%>
<% using (Html.BeginForm()) { %>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<div>
<fieldset>
<legend>Account Information</legend>

View File

@@ -9,7 +9,7 @@
<% if (Model != null && Model.Messages != null) Html.RenderPartial("Messages", Model.Messages); %>
<%= Html.ValidationSummary("Login was unsuccessful. Please correct the errors and try again.") %>
<% using (Html.BeginForm()) { %>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<div>
<fieldset>
<legend>Account Information</legend>

View File

@@ -10,7 +10,7 @@
</p>
<%= Html.ValidationSummary("Account creation was unsuccessful. Please correct the errors and try again.") %>
<% using (Html.BeginForm()) { %>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<div>
<fieldset>
<legend>Account Information</legend>

View File

@@ -3,11 +3,6 @@ using System.Web.Mvc;
namespace Orchard.Mvc.Filters {
public class AntiForgeryAuthorizationFilter : FilterProvider, IAuthorizationFilter {
public void OnAuthorization(AuthorizationContext filterContext) {
//TODO: (erikpo) Once all modules are moved over to use the AntiForgeryToken, get rid of this if statement
if (!(filterContext.RouteData.Values["area"] is string
&& (string)filterContext.RouteData.Values["area"] == "Orchard.Blogs"))
return;
if (!(filterContext.HttpContext.Request.HttpMethod == "POST" && filterContext.RequestContext.HttpContext.Request.IsAuthenticated))
return;

View File

@@ -199,7 +199,7 @@ namespace Orchard.Mvc.Html {
tagBuilder.MergeAttribute("action", formAction);
tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(formMethod), true);
htmlHelper.ViewContext.HttpContext.Response.Write(tagBuilder.ToString(TagRenderMode.StartTag));
htmlHelper.ViewContext.HttpContext.Response.Output.Write(tagBuilder.ToString(TagRenderMode.StartTag));
return new MvcFormAntiForgeryPost(htmlHelper);
}

View File

@@ -10,7 +10,7 @@ namespace Orchard.Mvc.Html {
}
protected override void Dispose(bool disposing) {
_htmlHelper.ViewContext.RequestContext.HttpContext.Response.Write(_htmlHelper.AntiForgeryTokenOrchard());
_htmlHelper.ViewContext.HttpContext.Response.Output.Write(_htmlHelper.AntiForgeryTokenOrchard());
base.Dispose(disposing);
}