如何克服对用户输入的恐惧(网络开发)

发布于 2024-08-15 09:39:25 字数 224 浏览 6 评论 0原文

我正在编写一个供公众使用的网络应用程序...您如何克服/处理对用户输入的恐惧?作为一名 Web 开发人员,您知道存在的技巧和漏洞,尤其是在 Web 上可以利用的技巧和漏洞,通过 Firebug 等附加组件变得更加容易。

有时,它是如此令人难以承受,您只想忘记整个交易(确实使不过,您很欣赏 Intranet 开发!)

抱歉,如果这不是一个可以简单回答的问题,但也许想法或策略会有所帮助......谢谢!

I'm writing a web application for public consumption...How do you get over/ deal with the fear of User Input? As a web developer, you know the tricks and holes that exist that can be exploited particularly on the web which are made all the more easier with add-ons like Firebug etc

Sometimes it's so overwhelming you just want to forget the whole deal (does make you appreciate Intranet Development though!)

Sorry if this isn't a question that can be answered simply, but perhaps ideas or strategies that are helpful...Thanks!

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

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

发布评论

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

评论(13

皇甫轩 2024-08-22 09:39:25

一个词:服务器端验证(好吧,这可能是三个词)。

One word: server-side validation (ok, that may have been three words).

╰つ倒转 2024-08-22 09:39:25

其他答案中有很多合理的建议,但我将添加一个不那么“编程”的答案:

制定处理计划。

为恶意用户确实设法偷偷过去的意外情况做好准备你。制定计划来减轻损害、恢复干净和完整的数据,并与用户(以及潜在的其他相关方,例如您持有的任何信用卡详细信息的发卡行)进行沟通,告诉他们发生了什么。了解如何检测漏洞并关闭它。要知道关键的运营和开发人员是可以联系到的,这样,在公共假期前的周五下午 5:01 发动攻击的坏人在您下线之前不会有 72 个以上的空闲时间,更不用说开始修复问题了。

制定适当的计划并不能帮助您阻止不良的用户输入,但它应该有助于克服您的恐惧。

There's lots of sound advice in other answers, but I'll add a less "programming" answer:

Have a plan for dealing with it.

Be ready for the contingency that malicious users do manage to sneak something past you. Have plans in place to mitigate damage, restore clean and complete data, and communicate with users (and potentially other interested parties such as the issuers of any credit card details you hold) to tell them what's going on. Know how you will detect the breach and close it. Know that key operational and development personnel are reachable, so that a bad guy striking at 5:01pm on the Friday before a public holiday won't get 72+ clear hours before you can go offline let alone start fixing things.

Having plans in place won't help you stop bad user input, but it should help a bit with overcoming your fears.

烟─花易冷 2024-08-22 09:39:25

如果您需要解决与“安全”相关的问题,那么安全和漏洞利用是软件中不可避免的事实,并且需要在开发过程中正面解决它们。

以下是一些建议:

  • 正确看待 - 任何流行或有用的应用程序都会发生安全性、漏洞利用和妥协,为它们做好准备并期望它们发生
  • 测试它,然后再次测试它 - 质量保证、验收测试和即使您是一家单人商店,签核也应该是您设计和生产过程中的一流部分。招募用户作为专门的(和有声的)用户进行测试将是您发现问题的最有用的工具。
  • 了解您的平台 - 确保您了解您正在部署的技术和硬件。确保相关补丁和安全更新经过应用
  • 研究 - 查看与您自己的应用程序类似的应用程序,看看他们遇到了什么问题,浏览他们的论坛,阅读他们的错误日志等。
  • 现实点 - 您将无法修复每个错误并且关闭每个孔。选择最有影响力的,并
  • 吸引尽可能多的人来审查您的设计和代码。这应该是您的 QA 资源的补充

If its "security" related concerns you need to just push through it, security and exploits are a fact of life in software, and they need to be addressed head-on as part of the development process.

Here are some suggestions:

  • Keep it in perspective - Security, Exploits and compromises are going to happen to any application which is popular or useful, be prepared for them and expect them to occur
  • Test it, then test it again - QA, Acceptance testing and sign off should be first class parts of your design and production process, even if you are a one-man shop. Enlist users to test as a dedicated (and vocal) user will be your most useful tool in finding problems
  • Know your platform - Make sure you know the technology, and hardware you are deploying on. Ensure that relevant patches and security updates are applied
  • research - look at applications similar to your own and see what issues they experience, surf their forums, read their bug logs etc.
  • Be realistic - You are not going to be able to fix every bug and close every hole. Pick the most impactful ones and address those
  • Lots of eyes - Enlist as many people to review your designs and code as possible. This should be in addition to your QA resources
迷爱 2024-08-22 09:39:25
  • 你无法克服它。
  • 检查服务器端的所有内容 - 再次验证输入、检查权限等。
  • 清理所有数据。

用粗体字写起来很容易,但在实践中却有点困难。

  • You don't get over it.
  • Check everything at server side - validate input again, check permissions, etc.
  • Sanitize all data.

That's very easy to write in bold letter and a little harder to do in practice.

分開簡單 2024-08-22 09:39:25

我经常做的事情是将所有用户字符串包装在一个对象中,例如 StringWrapper ,它强制您调用编码方法来获取字符串。换句话说,只需提供对 s.htmlEncode() s.urlEncode().htmlEncode() 等的访问即可。当然,您需要获取原始字符串,这样您就可以有一个 s.rawString() 方法,但现在您可以使用 grep 来查看原始字符串的所有使用。

因此,当您遇到“echo userString”时,您将收到类型错误,然后系统会提醒您通过公共方法对字符串进行编码/转义。

其他一些一般性的事情:

  • 优先使用白名单而不是黑名单
  • 不要过度剔除不良输入。我希望能够使用 <帖子/评论/等中的角色!只需确保正确编码数据
  • 即可使用参数化 SQL 查询。如果您自己使用 SQL 转义用户输入,那么您就做错了。

Something I always did was wrap all user strings in an object, something like StringWrapper which forces you to call an encoding method to get the string. In other words, just provide access to s.htmlEncode() s.urlEncode().htmlEncode() etc. Of course you need to get the raw string so you can have a s.rawString() method, but now you have something you can grep for to review all uses of raw strings.

So when you come to 'echo userString' you will get a type error, and you are then reminded to encode/escape the string through the public methods.

Some other general things:

  • Prefer white-lists over black lists
  • Don't go overboard with stripping out bad input. I want to be able to use the < character in posts/comments/etc! Just make sure you encode data correctly
  • Use parameterized SQL queries. If you are SQL escaping user input yourself, you are doing it wrong.
瑕疵 2024-08-22 09:39:25

首先,我会试图安慰你一点,指出偏执是件好事。正如开车时有点害怕是好事一样,害怕用户输入也是好事。尽可能做最坏的打算,你不会失望的。

其次,防御性编程。假设您与外界的任何通信都完全受到损害。仅接受用户应该能够控制的参数。仅公开用户应该能够看到的数据。

净化输入。消毒消毒消毒。如果它的输入将显示在网站上(排行榜的昵称、论坛上的消息等),请对其进行适当的清理。如果输入可能会发送到 SQL,也请对其进行清理。事实上,甚至不要直接编写 SQL,而是使用某种中介。

如果您使用 HTTP,实际上只有一件事是您无法防御的。如果您使用 cookie 来识别某人的身份,则您无法阻止咖啡馆中的其他人嗅探该咖啡馆中其他人的 cookie(如果他们都使用相同的无线连接)。只要他们不使用安全连接,就没有什么可以帮助您避免这种情况。即使 Gmail 也无法免受这种攻击。您唯一能做的就是确保授权 cookie 不会永远持续下去,并考虑让他们在做一些大事(例如更改密码或购买东西)之前重新登录。

但别担心。许多安全细节已经由您在其上构建的任何系统处理(您正在构建在某些东西之上,不是吗?Spring MVC?Rails?Struts?)。这真的没那么难。如果涉及大笔资金,您可以付费聘请安全审计公司来尝试破解它。如果没有,就试着想出一切合理的办法,并在发现漏洞时修复它们。

但不要停止偏执。他们总是出去找你。这只是受欢迎的一部分。

PS 还有一个提示。如果你有这样的 JavaScript:

if( document.forms["myForm"]["payment"].value < 0 ) {
  alert("You must enter a positive number!");
  return false;
}

那么你肯定在后端有这样的代码:

verify( input.payment >= 0 )

First, I'll try to comfort you a bit by pointing out that it's good to be paranoid. Just as it's good to be a little scared while driving, it's good to be afraid of user input. Assume the worst as much as you can, and you won't be disappointed.

Second, program defensively. Assume any communication you have with the outside world is entirely compromised. Take in only parameters that the user should be able to control. Expose only that data that the user should be able to see.

Sanitize input. Sanitize sanitize sanitize. If it's input that will be displayed on the site (nicknames for a leaderboard, messages on a forum, anything), sanitize it appropriately. If it's input that might be sent to SQL, sanitize that too. In fact, don't even write SQL directly, use an intermediary of some sort.

There's really only one thing you can't defend from if you're using HTTP. If you use a cookie to identify somebody's identity, there's nothing you can do from preventing somebody else in a coffeehouse from sniffing the cookie of somebody else in that coffee house if they're both using the same wireless connection. As long as they're not using a secure connection, nothing can save you from that. Even Gmail isn't safe from that attack. The only thing you can do is make sure an authorization cookie can't last forever, and consider making them re-login before they do something big like change password or buy something.

But don't sweat it. A lot of the security details have been taken care of by whatever system you're building on top of (you ARE building on top of SOMETHING, aren't you? Spring MVC? Rails? Struts? ). It's really not that tough. If there's big money at stake, you can pay a security auditing company to try and break it. If there's not, just try to think of everything reasonable and fix holes when they're found.

But don't stop being paranoid. They're always out to get you. That's just part of being popular.

P.S. One more hint. If you have javascript like this:

if( document.forms["myForm"]["payment"].value < 0 ) {
  alert("You must enter a positive number!");
  return false;
}

Then you'd sure as hell have code in the backend that goes:

verify( input.payment >= 0 )
眼波传意 2024-08-22 09:39:25

“引用”所有内容,使其在“目标”语言中没有任何含义:SQL、HTML、JavaScript 等。

这当然会造成妨碍,因此您必须小心确定何时需要特殊处理,就像通过管理权限来处理一些如果数据一样。

"Quote" everything so that it can not have any meaning in the 'target' language: SQL, HTML, JavaScript, etc.

This will get in the way of course, so you have to be careful to identify when this needs special handling, like through administrative privileges to deal with some if the data.

亚希 2024-08-22 09:39:25

有多种类型的注入和跨站点脚本(请参阅这个早期的答案),但对所有这些都有防御措施。首先,您显然需要查看存储过程、白名单(例如,用于 HTML 输入)和验证。

除此之外,很难给出一般性建议。其他人给出了一些很好的建议,例如始终进行服务器端验证和研究过去的攻击。

保持警惕,但不要害怕。

There are multiple types of injection and cross-site scripting (see this earlier answer), but there are defenses against all of them. You'll clearly want to look at stored procedures, white-listing (e.g. for HTML input), and validation, to start.

Beyond that, it's hard to give general advice. Other people have given some good tips, such as always doing server-side validation and researching past attacks.

Be vigilant, but not afraid.

瑾夏年华 2024-08-22 09:39:25
  • Web 应用程序层没有验证。
  • 所有验证和安全检查应由领域层或业务层完成。
  • 抛出带有有效错误消息的异常,并让这些异常在表示层或 Web 应用程序中被捕获和处理。

您可以使用验证框架
在帮助下自动验证
自定义验证属性。

http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=477

  • No validation in web-application layer.
  • All validations and security checks should be done by the domain layer or business layer.
  • Throw exceptions with valid error messages and let these execptions be caught and processed at presentation layer or web-application.

You can use validation framework
to automate validations with the help
of custom validation attributes.

http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=477

请远离我 2024-08-22 09:39:25

应该有一些关于您正在使用的语言/系统的已知漏洞的文档。我知道 Zend PHP 认证稍微涵盖了这个问题,您可以阅读学习指南。

为什么不聘请专家时常审核您的申请呢?考虑到您的关注程度,这是一项值得的投资。

There should be some documentation of known exploits for the language/system you're using. I know the Zend PHP Certification covers that issue a bit and you can read the study guide.

Why not hire an expert to audit your applications from time to time? It's a worthwhile investment considering your level of concern.

許願樹丅啲祈禱 2024-08-22 09:39:25

我们的客户总是说:“与我的用户打交道,因为他们不区分日期和文本字段!!”

我用 Java 编写代码,我的代码充满了断言,我认为客户端的一切都是错误的,我在服务器上检查了一切。

Our client always say: "Deal with my users as they dont differentiate between the date and text fields!!"

I code in Java, and my code is full of asserts i assume everything is wrong from the client and i check it all at server.

聆听风音 2024-08-22 09:39:25

对我来说,第一件事就是始终构建静态 SQL 查询并将数据作为参数传递。这极大地限制了您必须处理的报价问题。另请参阅 http://xkcd.com/327/

这也具有性能优势,因为您可以重新使用准备好的查询。

#1 thing for me is to always construct static SQL queries and pass your data as parameters. This limits the quoting issues you have to deal with enormously. See also http://xkcd.com/327/

This also has performance benefits, as you can re-use the prepared queries.

吃素的狼 2024-08-22 09:39:25

实际上,您只需要注意两件事:

  1. 避免SQL 注入。使用参数化查询将用户控制的输入保存在数据库中。用 Java 术语来说:使用 PreparedStatement< /a>.用 PHP 术语来说:使用 mysql_real_escape_string()PDO

  2. 避免XSS。在显示期间转义用户控制的输入。在 Java/JSP 术语中:使用 JSTL 。用 PHP 术语来说:使用 htmlspecialchars()

就这样。您无需担心数据的格式。只是关于你如何处理它的方式。

There are actually only 2 things you need to take care with:

  1. Avoid SQL injection. Use parameterized queries to save user-controlled input in database. In Java terms: use PreparedStatement. In PHP terms: use mysql_real_escape_string() or PDO.

  2. Avoid XSS. Escape user-controlled input during display. In Java/JSP terms: use JSTL <c:out>. In PHP terms: use htmlspecialchars().

That's all. You don't need to worry about the format of the data. Just about the way how you handle it.

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