首页 文章

确定HTTP请求是否是HttpApplication.AuthenticateRequest上的soap请求

提问于
浏览
3

我有办法知道请求是否是针对HttpApplication的AuthenticateRequest事件的soap请求?检查ServerVariables [“HTTP_SOAPACTION”]似乎不能一直工作 .

public void Init(HttpApplication context) {
    context.AuthenticateRequest += new EventHandler(AuthenticateRequest);
}

protected void AuthenticateRequest(object sender, EventArgs e) {
    app = sender as HttpApplication;
    if (app.Request.ServerVariables["HTTP_SOAPACTION"] != null) {
        // a few requests do not enter here, but my webservice class still executing
        // ...
    }
}

我在web.config文件中禁用了HTTP POST和HTTP GET for webservices .

<webServices>
    <protocols>
      <remove name="HttpGet" />
           <remove name="HttpPost" />
      <add name="AnyHttpSoap" />
    </protocols>
</webServices>

查看soap xml的ContentType只能部分解决我的问题 . 例如,

Cache-Control: no-cache
Connection: Keep-Alive
Content-Length: 1131
Content-Type: text/xml
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: ro
Host: localhost
mymethod: urn:http://www.wsnamespace.com/myservice

一些客户端而不是标准头SOAPAction:“_ http://www.wsnamespace.com/myservice/mymethod ", have someting like in example above. " mymethod " represents the method in my web service class with [WebMethod] attribute on it and " http://www.wsnamespace.com/myservice”是Web服务的命名空间 . 服务仍然完全正常 . 消费者使用不同的框架(来自PHP,.NET,Java等的NuSOAP) .

5 回答

  • 0

    你测试过System.Web.HttpContext.Current.Request.CurrentExecutionFilePathExtension吗?通常,对于webservices(json和xml),这将是.asmx,只要你当然处理服务 .

  • 0

    您可以查看 Request.ContentType 属性,如果客户端正确设置了该属性

    application/soap+xml; charset=utf-8
    

    utf-8部分可能不存在 .

    除此之外,你肯定可以检查URL,如果它是一个web服务,那么它会告诉你它是什么 .

  • 2

    我总是给自己的端口提供Web服务 . 这样我就不必过滤每个通过端口80发出的HTTP请求 . 或者说,我可以过滤端口80以解决面向浏览器的问题,以及SOAP / SOA端口用于其他类型的攻击 .

    IMAO,将(可能)敏感的业务数据与公共数据混合在一起,这样您就不必在防火墙上打开另一个漏洞了,因为您首先要使用防火墙 .

  • 0

    您还可以沿着更难的路线走下去,根据HTTP标头下面的其他内容来解决问题 . 我的意思是,分析下面的内容,这是SOAP请求主体 - 请求的一部分......

    <soap:Envelope xmlns:soap="..." soap:encodingStyle="...">
    

    IBM

  • 0

    我使用以下代码来标识请求类型 . 如果它符合您的要求,请尝试此操作 . 如果有帮助,请标记为答案 .

    if (request.Headers["SOAPAction"] != null || request.ContentType.StartsWith("application/soap+xml"))
        return ServiceRequestTypes.SoapRequest;
    else if ("POST".Equals(request.RequestType, StringComparison.InvariantCultureIgnoreCase) && request.ContentType.StartsWith("application/x-www-form-urlencoded", StringComparison.InvariantCultureIgnoreCase))
        return ServiceRequestTypes.HttpPostRequest;
    else if ("POST".Equals(request.RequestType, StringComparison.InvariantCultureIgnoreCase) && request.ContentType.StartsWith("application/json", StringComparison.InvariantCultureIgnoreCase))
        return ServiceRequestTypes.AjaxScriptServiceRequest;
    return ServiceRequestTypes.Unknown;
    

相关问题