【发布时间】:2012-03-07 21:39:44
【问题描述】:
我需要对 WCF 服务上的“帮助”网址应用一组不同的安全策略。如何获取 WCF 服务的完整 URL .. 即 Session 或 Session.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");
}
}
【问题讨论】:
-
“这里的作者建议我简单地检查字符串是否以“帮助”结尾,然后盲目地允许该查询(这显然是不正确的)”。是的,因为
http://example.com/extremely-sensitive-page?now-i-pwn-you=help应该不受安全策略的约束。 -
只是为了澄清外行......迈克在讽刺;)
标签: wcf security authentication token httpcontext