例如,如果您有一个类似CSPdefault-src 'self'; report-uri /CspViolationReport
且/CspViolationReport
由ASP.Net处理的CSP,您如何访问已发布的CSP违规报告?
我们希望找到一些发布的JSON,例如http://www.w3.org/TR/CSP11/#example-violation-report
当您检查时Request.Form
,没有键,并且中也没有证据Request.ServerVariables["ALL_RAW"]
,而是Request.ServerVariables["HTTP_METHOD"]
“ POST”。
通过Fiddler截取POST,您可以看到JSON确实已发布,但是.Net似乎无法让您看到它。
这是受http://muaz-khan.blogspot.co.nz/2012/06/exploring-csp-content-security-policy.html启发的一种方法,谢谢!
void ProcessCspValidationReport() {
Request.InputStream.Position = 0;
using (StreamReader inputStream = new StreamReader(Request.InputStream))
{
string s = inputStream.ReadToEnd();
if (!string.IsNullOrWhiteSpace(s))
{
CspPost cspPost = JsonConvert.DeserializeObject<CspPost>(s);
//now you can access properties of cspPost.CspReport
}
}
}
class CspPost
{
[JsonProperty("csp-report")]
public CspReport CspReport { get; set; }
}
class CspReport
{
[JsonProperty("document-uri")]
public string DocumentUri { get; set; }
[JsonProperty("referrer")]
public string Referrer { get; set; }
[JsonProperty("effective-directive")]
public string EffectiveDirective { get; set; }
[JsonProperty("violated-directive")]
public string ViolatedDirective { get; set; }
[JsonProperty("original-policy")]
public string OriginalPolicy { get; set; }
[JsonProperty("blocked-uri")]
public string BlockedUri { get; set; }
[JsonProperty("source-file")]
public string SourceFile { get; set; }
[JsonProperty("line-number")]
public int LineNumber { get; set; }
[JsonProperty("column-number")]
public int ColumnNumber { get; set; }
[JsonProperty("status-code")]
public string StatusCode { get; set; }
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句