【问题标题】:Modifing CheckAccessCore(ctx) to permit WCF Help pages w/o authentication修改 CheckAccess Core(ktx) 以允许 WCF 帮助页面无需身份验证
【发布时间】:2012-03-07 21:39:44
【问题描述】:

我需要对 WCF 服务上的“帮助”网址应用一组不同的安全策略。如何获取 WCF 服务的完整 URL .. 即 SessionSession.svc

http://localhost:62302/Session.svc/help
http://localhost:62302/Session.svc/help/operations/GetSession
http://localhost:62302/Session/help
http://localhost:62302/Session/help/operations/GetSession

由于这与安全相关,我需要审查我提出的任何反对社区的意见。 The author here suggests 我只是检查字符串是否以“帮助”结尾,然后盲目地允许该查询(这显然是不正确的)

代码片段

public class APIKeyAuthorization : ServiceAuthorizationManager
{
     protected override bool CheckAccessCore(OperationContext operationContext)
    {
        if (this.IsHelpPage(operationContext.RequestContext.RequestMessage) || IsValidAPIKey(operationContext))
        {
            return true;
        }
        else
        {
            string key = GetAPIKey(operationContext);

            // Send back an HTML reply
            CreateErrorReply(operationContext, key);
            return false;
        }
    }

    private bool IsHelpPage(Message requestMessage)
    {
        return requestMessage.Headers.To.AbsolutePath.ToLower().EndsWith("help");
    }
 }

full source

【问题讨论】:

  • “这里的作者建议我简单地检查字符串是否以“帮助”结尾,然后盲目地允许该查询(这显然是不正确的)”。是的,因为http://example.com/extremely-sensitive-page?now-i-pwn-you=help 应该不受安全策略的约束。
  • 只是为了澄清外行......迈克在讽刺;)

标签: wcf security authentication token httpcontext


【解决方案1】:

这可能过于简化了您最初的问题,但为什么不将帮助部分放在它自己的未受保护区域中呢?您可以创建一个帮助控制器,其唯一目的是提供帮助页面。然后,您需要配置 web.config 以允许用户无需身份验证即可访问帮助部分。同样,这可能过于简化了,但值得一试。

【讨论】:

    猜你喜欢
    • 2023-03-12
    • 2011-04-08
    • 1970-01-01
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    相关资源
    最近更新 更多