CAT.NET:漏洞还是误报?

发布于 2024-10-10 11:11:09 字数 390 浏览 4 评论 0原文

偶尔系列中的第二个: 这是第一个

CAT.NET 认为以下内容是 ASP.NET 中的真正漏洞还是误报,这是否正确?

var myInt = Int32.Parse(txtUserInput.Text);

Response.Redirect(string.Format("myPage.aspx?myId={0}", myInt);

CAT.NET 将此报告为重定向漏洞,需要通过编码 myInt 进行修复。

2nd in an occasional series:
Here's the first one

Is CAT.NET correct that the following is a genuine vulnerability in ASP.NET or is it a false positive?

var myInt = Int32.Parse(txtUserInput.Text);

Response.Redirect(string.Format("myPage.aspx?myId={0}", myInt);

CAT.NET is reporting this as a redirect vulnerability needing remediation via encoding myInt.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

静赏你的温柔 2024-10-17 11:11:09

我不会称其为危险,但它不是我自己编写的方式,

int myInt;
if(Int32.TryParse(txtUserInput.Text,out myInt)){
    Response.Redirect(string.Format("myPage.aspx?myId={0}", myInt);
   }

在我看来更干净,因为如果由于用户输入错误而解析失败并且我们显式键入 int,它不会抛出异常。

任何错误处理代码都可以捆绑到最后的 else 语句中。

I wouldn't call that dangerous but its not how I would write it myself

int myInt;
if(Int32.TryParse(txtUserInput.Text,out myInt)){
    Response.Redirect(string.Format("myPage.aspx?myId={0}", myInt);
   }

Is to my mind cleaner as it wont throw an exception if the parse fails due to bad user input and we are explicitly typing the int.

Any error handling code can be bundled into an else statement on the end.

浅浅 2024-10-17 11:11:09

我不相信,它可能会导致异常,所以 TryParse 可能是更好的方法。这只是大喊大叫,因为您正在获取用户输入并根据它进行重定向。它可能有点太激进了,但这并不完全是坏事。

I don't believe so, it could cause an exception so TryParse might be a better approach. It's just yelling because you are taking user input and redirecting based on it. It's possibly being a little too aggressive which isn't exactly bad.

烏雲後面有陽光 2024-10-17 11:11:09

此代码不存在可利用的漏洞。任何漏洞都可能是 myPage.aspx 对 myId 值执行操作的结果,而不是您的 url 的构建方式。任何人都可以轻松地在查询字符串中使用他们想要的任何内容直接点击 myPage.aspx。

然而,这是一个不好的做法,假设您没有在这两行之间的代码中遗漏任何内容。您应该验证 txtUserInput.Text 是否仅包含数字字符,并且在允许的值范围内。

漏洞的发生是由于用户提供的数据被发布到的页面对其进行了不正确的解析,而不是 URL 的不正确生成。虽然尝试确保您的网站不会因为表单中的某些内容而编写损坏的 URL 是个好主意,但前端的输入验证与安全性无关。重要的是接受输入的代码如何处理它,因为任何帖子或查询字符串都可以伪造。

There is no exploitable vulnerability as a result of this code. Any vulnerability would be a result of what myPage.aspx does with the value of myId, not how your url is built. Anyone could just as easily directly hit myPage.aspx with anything they want in the querystring.

However this is bad practice, assuming that you haven't left anything out of the code between those two lines. You should verify that txtUserInput.Text contains only numeric characters, and falls within allowable values.

Exploits happen because of improper parsing of user-supplied data by the page it's posted to -- not improper generating of URLs. While it's a good idea to try to make sure your web site won't write a broken URL because of something that's put in a form, input validation at the front-end is irrelevant to security. All that matters is what the code that accepts the input does with it, since any post or query string can be forged.

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