mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +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
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Dashboard
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Feeds
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: HomePage
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Navigation
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Scheduling
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Settings
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Themes
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
Name: XmlRpc
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Widgets
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Blogs
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Comments
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Media
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Pages
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Roles
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Setup
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Tags
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: Users
|
||||
antiforgery: enabled
|
@@ -1 +1,2 @@
|
||||
name: TinyMce
|
||||
antiforgery: enabled
|
@@ -22,5 +22,6 @@
|
||||
public string Author { get; set; }
|
||||
public string HomePage { get; set; }
|
||||
public string Tags { get; set; }
|
||||
public string AntiForgery { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -57,7 +57,8 @@ namespace Orchard.Extensions {
|
||||
Version = GetValue(fields, "version"),
|
||||
Author = GetValue(fields, "author"),
|
||||
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.Web;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Extensions;
|
||||
using Orchard.Mvc.Filters;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
@@ -11,26 +13,46 @@ namespace Orchard.Mvc.AntiForgery {
|
||||
public class AntiForgeryAuthorizationFilter : FilterProvider, IAuthorizationFilter {
|
||||
private readonly ISiteService _siteService;
|
||||
private readonly IAuthenticationService _authenticationService;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
|
||||
public AntiForgeryAuthorizationFilter(ISiteService siteService, IAuthenticationService authenticationService) {
|
||||
public AntiForgeryAuthorizationFilter(ISiteService siteService, IAuthenticationService authenticationService, IExtensionManager extensionManager) {
|
||||
_siteService = siteService;
|
||||
_authenticationService = authenticationService;
|
||||
_extensionManager = extensionManager;
|
||||
}
|
||||
|
||||
public void OnAuthorization(AuthorizationContext filterContext) {
|
||||
#if false
|
||||
if ((filterContext.HttpContext.Request.HttpMethod != "POST" ||
|
||||
_authenticationService.GetAuthenticatedUser() == null) && !ShouldValidateGet(filterContext)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsAntiForgeryProtectionEnabled(filterContext)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var siteSalt = _siteService.GetSiteSettings().SiteSalt;
|
||||
var validator = new ValidateAntiForgeryTokenAttribute {Salt = siteSalt};
|
||||
validator.OnAuthorization(filterContext);
|
||||
|
||||
if (filterContext.HttpContext is HackHttpContext)
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user