我们应该如何验证 aspx .net 中的 http 标头引用地址
我想确保错误页面上的引荐来源网址中不会出现任何异常情况。
我应该检查什么才能验证 http 标头。
下面是我当前的代码:
// Ensure the referrer header is good
if (this.Request.UrlReferrer.IsWellFormedOriginalString() &&
this.Request.UrlReferrer.Host.Equals(this.Request.Url.Host))
{
这将使使用 %3C 和 %3E 而不是 << 的 acunetix 扫描失败。 和> 例如,我显然需要涵盖 html 编码 - 还有什么我遗漏的吗?
更新 我可以使用下面的代码捕获所有 acunetix 扫描:
if (this.Request.UrlReferrer.IsWellFormedOriginalString() &&
this.Request.UrlReferrer.Host.Equals(this.Request.Url.Host) &&
!Regex.IsMatch(this.Request.UrlReferrer.ToString(),
"%3C",
RegexOptions.IgnoreCase))
{
I want to ensure ensure nothing untoward gets into the referrer on an error page.
What should I be checking in order to validate the http header.
below is my current code:
// Ensure the referrer header is good
if (this.Request.UrlReferrer.IsWellFormedOriginalString() &&
this.Request.UrlReferrer.Host.Equals(this.Request.Url.Host))
{
this will fail an acunetix scan that uses %3C and %3E instead of < and > for example so I obviously need to cover html encoding - is there anything else I am missing?
Update
I can catch all the acunetix scans using the code below:
if (this.Request.UrlReferrer.IsWellFormedOriginalString() &&
this.Request.UrlReferrer.Host.Equals(this.Request.Url.Host) &&
!Regex.IsMatch(this.Request.UrlReferrer.ToString(),
"%3C",
RegexOptions.IgnoreCase))
{
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
然后始终对输出到错误页面的任何字符串(包括引用 URL)进行 HTML 转义。
尝试根据具体情况挑选出包含潜在危险字符的输入并将其列入黑名单是一种倒退。 您可能无法捕获所有可能的攻击,并且您将不必要地禁止有效的 URL。 (URL 中包含“%3C”是完全合理的。)
Then always HTML-escape any string — including referrer URLs — that you output to the error page.
Trying to pick out and blacklist input containing potentially dangerous characters on a case-by-case basis is doing it backwards. You probably won't catch all possible attacks, and you'll unnecessarily disallow valid URLs. (It's perfectly reasonable to have a URL with ‘%3C’ in.)
如果未提供或未参与推荐人,则 this.Request.UrlReferrer 可能为 null。
this.Request.UrlReferrer may be null, if no referrer was provided or has participated.