mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
- AntiForgerFilter now opt-in for Orchard extensions such as modules and areas.
- "antiforgery: enabled" in your module.txt will enable the filter to do the antiforgery check on posts. --HG-- branch : dev
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
Name: Common
|
Name: Common
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Dashboard
|
name: Dashboard
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Feeds
|
name: Feeds
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: HomePage
|
name: HomePage
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Navigation
|
name: Navigation
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Scheduling
|
name: Scheduling
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Settings
|
name: Settings
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Themes
|
name: Themes
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
Name: XmlRpc
|
Name: XmlRpc
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Widgets
|
name: Widgets
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Blogs
|
name: Blogs
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Comments
|
name: Comments
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Media
|
name: Media
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Pages
|
name: Pages
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Roles
|
name: Roles
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Setup
|
name: Setup
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Tags
|
name: Tags
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: Users
|
name: Users
|
||||||
|
antiforgery: enabled
|
||||||
@@ -1 +1,2 @@
|
|||||||
name: TinyMce
|
name: TinyMce
|
||||||
|
antiforgery: enabled
|
||||||
@@ -22,5 +22,6 @@
|
|||||||
public string Author { get; set; }
|
public string Author { get; set; }
|
||||||
public string HomePage { get; set; }
|
public string HomePage { get; set; }
|
||||||
public string Tags { get; set; }
|
public string Tags { get; set; }
|
||||||
|
public string AntiForgery { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ namespace Orchard.Extensions {
|
|||||||
Version = GetValue(fields, "version"),
|
Version = GetValue(fields, "version"),
|
||||||
Author = GetValue(fields, "author"),
|
Author = GetValue(fields, "author"),
|
||||||
HomePage = GetValue(fields, "homepage"),
|
HomePage = GetValue(fields, "homepage"),
|
||||||
Tags = GetValue(fields, "tags")
|
Tags = GetValue(fields, "tags"),
|
||||||
|
AntiForgery = GetValue(fields, "antiforgery")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Orchard.Extensions;
|
||||||
using Orchard.Mvc.Filters;
|
using Orchard.Mvc.Filters;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
using Orchard.Settings;
|
using Orchard.Settings;
|
||||||
@@ -11,26 +13,46 @@ namespace Orchard.Mvc.AntiForgery {
|
|||||||
public class AntiForgeryAuthorizationFilter : FilterProvider, IAuthorizationFilter {
|
public class AntiForgeryAuthorizationFilter : FilterProvider, IAuthorizationFilter {
|
||||||
private readonly ISiteService _siteService;
|
private readonly ISiteService _siteService;
|
||||||
private readonly IAuthenticationService _authenticationService;
|
private readonly IAuthenticationService _authenticationService;
|
||||||
|
private readonly IExtensionManager _extensionManager;
|
||||||
|
|
||||||
public AntiForgeryAuthorizationFilter(ISiteService siteService, IAuthenticationService authenticationService) {
|
public AntiForgeryAuthorizationFilter(ISiteService siteService, IAuthenticationService authenticationService, IExtensionManager extensionManager) {
|
||||||
_siteService = siteService;
|
_siteService = siteService;
|
||||||
_authenticationService = authenticationService;
|
_authenticationService = authenticationService;
|
||||||
|
_extensionManager = extensionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAuthorization(AuthorizationContext filterContext) {
|
public void OnAuthorization(AuthorizationContext filterContext) {
|
||||||
#if false
|
|
||||||
if ((filterContext.HttpContext.Request.HttpMethod != "POST" ||
|
if ((filterContext.HttpContext.Request.HttpMethod != "POST" ||
|
||||||
_authenticationService.GetAuthenticatedUser() == null) && !ShouldValidateGet(filterContext)) {
|
_authenticationService.GetAuthenticatedUser() == null) && !ShouldValidateGet(filterContext)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!IsAntiForgeryProtectionEnabled(filterContext)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var siteSalt = _siteService.GetSiteSettings().SiteSalt;
|
var siteSalt = _siteService.GetSiteSettings().SiteSalt;
|
||||||
var validator = new ValidateAntiForgeryTokenAttribute {Salt = siteSalt};
|
var validator = new ValidateAntiForgeryTokenAttribute {Salt = siteSalt};
|
||||||
validator.OnAuthorization(filterContext);
|
validator.OnAuthorization(filterContext);
|
||||||
|
|
||||||
if (filterContext.HttpContext is HackHttpContext)
|
if (filterContext.HttpContext is HackHttpContext)
|
||||||
filterContext.HttpContext = ((HackHttpContext)filterContext.HttpContext).OriginalHttpContextBase;
|
filterContext.HttpContext = ((HackHttpContext)filterContext.HttpContext).OriginalHttpContextBase;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
private bool IsAntiForgeryProtectionEnabled(ControllerContext context) {
|
||||||
|
string currentModule = context.RouteData.Values["area"].ToString();
|
||||||
|
if (!String.IsNullOrEmpty(currentModule)) {
|
||||||
|
foreach (var descriptor in _extensionManager.AvailableExtensions()) {
|
||||||
|
if (String.Equals(descriptor.Name, currentModule, StringComparison.OrdinalIgnoreCase)) {
|
||||||
|
if (String.Equals(descriptor.AntiForgery, "enabled", StringComparison.OrdinalIgnoreCase)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ShouldValidateGet(AuthorizationContext context) {
|
private static bool ShouldValidateGet(AuthorizationContext context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user