我们应该如何验证 aspx .net 中的 http 标头引用地址

发布于 2024-07-15 03:12:57 字数 743 浏览 4 评论 0原文

我想确保错误页面上的引荐来源网址中不会出现任何异常情况。

我应该检查什么才能验证 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦幻的味道 2024-07-22 03:12:57

我想确保错误页面上的引荐来源网址中不会出现任何异常情况。

然后始终对输出到错误页面的任何字符串(包括引用 URL)进行 HTML 转义。

尝试根据具体情况挑选出包含潜在危险字符的输入并将其列入黑名单是一种倒退。 您可能无法捕获所有可能的攻击,并且您将不必要地禁止有效的 URL。 (URL 中包含“%3C”是完全合理的。)

I want to ensure ensure nothing untoward gets into the referrer on an error page.

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.)

回梦 2024-07-22 03:12:57

如果未提供或未参与推荐人,则 this.Request.UrlReferrer 可能为 null。

this.Request.UrlReferrer may be null, if no referrer was provided or has participated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文