Skip to content

Commit b0405f8

Browse files
Merge pull request rails#55314 from duffuniverse/fix-stale-links-in-securing-rails-apps-guide
[ci skip] Fix stale links in the Securing Rails Applications guide
2 parents ea11c2f + 76d18db commit b0405f8

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

guides/source/security.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ been added in `routes.rb`), you'll see a form that accepts an email and a
100100
password with "sign in" button. This form routes to the `SessionsController`
101101
which was added by the generator. If you provide an email/password for a user
102102
that exists in the database, you will be able to successfully authenticate with
103-
those credentials and login to the application.
103+
those credentials and log in to the application.
104104

105105
NOTE: After running the Authentication generator, you do need to implement your
106106
own *sign up flow* and add the necessary views, routes, and controller actions.
@@ -389,7 +389,7 @@ NOTE: _Apart from stealing a user's session ID, the attacker may fix a session I
389389
390390
This attack focuses on fixing a user's session ID known to the attacker, and forcing the user's browser into using this ID. It is therefore not necessary for the attacker to steal the session ID afterwards. Here is how this attack works:
391391
392-
* The attacker creates a valid session ID: They load the login page of the web application where they want to fix the session, and take the session ID in the cookie from the response (see number 1 and 2 in the image).
392+
* The attacker creates a valid session ID: They load the login page of the web application where they want to fix the session, and take the session ID in the cookie from the response (see numbers 1 and 2 in the image).
393393
* They maintain the session by accessing the web application periodically in order to keep an expiring session alive.
394394
* The attacker forces the user's browser into using this session ID (see number 3 in the image). As you may not change a cookie of another domain (because of the same origin policy), the attacker has to run a JavaScript from the domain of the target web application. Injecting the JavaScript code into the application by XSS accomplishes this attack. Here is an example: `<script>document.cookie="_session_id=16d5b78abb28e3d6206b60f22a03c8d9";</script>`. Read more about XSS and injection later on.
395395
* The attacker lures the victim to the infected page with the JavaScript code. By viewing the page, the victim's browser will change the session ID to the trap session ID.
@@ -571,7 +571,7 @@ def legacy
571571
end
572572
```
573573

574-
This will redirect the user to the main action if they tried to access a legacy action. The intention was to preserve the URL parameters to the legacy action and pass them to the main action. However, it can be exploited by attacker if they included a host key in the URL:
574+
This will redirect the user to the main action if they try to access a legacy action. The intention was to preserve the URL parameters to the legacy action and pass them to the main action. However, it can be exploited by an attacker if they include a host key in the URL:
575575

576576
```
577577
http://www.example.com/site/legacy?param1=xy&param2=23&host=www.attacker.com
@@ -601,7 +601,7 @@ def sanitize_filename(filename)
601601
# NOTE: File.basename doesn't work right with Windows paths on Unix
602602
# get only the filename, not the whole path
603603
name.sub!(/\A.*(\\|\/)/, "")
604-
# Finally, replace all non alphanumeric, underscore
604+
# Finally, replace all non-alphanumeric, underscore
605605
# or periods with underscore
606606
name.gsub!(/[^\w.-]/, "_")
607607
end
@@ -639,7 +639,7 @@ raise if basename != File.expand_path(File.dirname(filename))
639639
send_file filename, disposition: "inline"
640640
```
641641

642-
Another (additional) approach is to store the file names in the database and name the files on the disk after the ids in the database. This is also a good approach to avoid possible code in an uploaded file to be executed. The `attachment_fu` plugin does this in a similar way.
642+
Another (additional) approach is to store the file names in the database and name the files on the disk after the ids in the database. This is also a good approach to avoid possible code in an uploaded file from being executed. The `attachment_fu` plugin does this in a similar way.
643643

644644
User Management
645645
---------------
@@ -688,7 +688,7 @@ Depending on your web application, there may be more ways to hijack the user's a
688688

689689
### CAPTCHAs
690690

691-
INFO: _A CAPTCHA is a challenge-response test to determine that the response is not generated by a computer. It is often used to protect registration forms from attackers and comment forms from automatic spam bots by asking the user to type the letters of a distorted image. This is the positive CAPTCHA, but there is also the negative CAPTCHA. The idea of a negative CAPTCHA is not for a user to prove that they are human, but reveal that a robot is a robot._
691+
INFO: _A CAPTCHA is a challenge-response test to determine that the response is not generated by a computer. It is often used to protect registration forms from attackers and comment forms from automatic spam bots by asking the user to type the letters of a distorted image. This is the positive CAPTCHA, but there is also the negative CAPTCHA. The idea of a negative CAPTCHA is not for a user to prove that they are human, but to reveal that a robot is a robot._
692692

693693
A popular positive CAPTCHA API is [reCAPTCHA](https://developers.google.com/recaptcha/) which displays two distorted images of words from old books. It also adds an angled line, rather than a distorted background and high levels of warping on the text as earlier CAPTCHAs did, because the latter were broken. As a bonus, using reCAPTCHA helps to digitize old books. [ReCAPTCHA](https://github.com/ambethia/recaptcha/) is also a Rails plug-in with the same name as the API.
694694

@@ -699,13 +699,13 @@ Most bots are really naive. They crawl the web and put their spam into every for
699699

700700
Note that negative CAPTCHAs are only effective against naive bots and won't suffice to protect critical applications from targeted bots. Still, the negative and positive CAPTCHAs can be combined to increase the performance, e.g., if the "honeypot" field is not empty (bot detected), you won't need to verify the positive CAPTCHA, which would require an HTTPS request to Google ReCaptcha before computing the response.
701701

702-
Here are some ideas how to hide honeypot fields by JavaScript and/or CSS:
702+
Here are some ideas on how to hide honeypot fields by JavaScript and/or CSS:
703703

704-
* position the fields off of the visible area of the page
704+
* position the fields off the visible area of the page
705705
* make the elements very small or color them the same as the background of the page
706706
* leave the fields displayed, but tell humans to leave them blank
707707

708-
The most simple negative CAPTCHA is one hidden honeypot field. On the server side, you will check the value of the field: If it contains any text, it must be a bot. Then, you can either ignore the post or return a positive result, but not saving the post to the database. This way the bot will be satisfied and moves on.
708+
The simplest negative CAPTCHA is one hidden honeypot field. On the server side, you will check the value of the field: If it contains any text, it must be a bot. Then, you can either ignore the post or return a positive result, but not save the post to the database. This way, the bot will be satisfied and move on.
709709

710710
You can find more sophisticated negative CAPTCHAs in Ned Batchelder's [blog post](https://nedbatchelder.com/text/stopbots.html):
711711

@@ -719,7 +719,7 @@ Note that this protects you only from automatic bots, targeted tailor-made bots
719719

720720
WARNING: _Tell Rails not to put passwords in the log files._
721721

722-
By default, Rails logs all requests being made to the web application. But log files can be a huge security issue, as they may contain login credentials, credit card numbers et cetera. When designing a web application security concept, you should also think about what will happen if an attacker got (full) access to the web server. Encrypting secrets and passwords in the database will be quite useless, if the log files list them in clear text. You can _filter certain request parameters from your log files_ by appending them to [`config.filter_parameters`][] in the application configuration. These parameters will be marked [FILTERED] in the log.
722+
By default, Rails logs all requests being made to the web application. But log files can be a huge security issue, as they may contain login credentials, credit card numbers et cetera. When designing a web application security concept, you should also think about what will happen if an attacker gets (full) access to the web server. Encrypting secrets and passwords in the database will be quite useless, if the log files list them in clear text. You can _filter certain request parameters from your log files_ by appending them to [`config.filter_parameters`][] in the application configuration. These parameters will be marked [FILTERED] in the log.
723723

724724
```ruby
725725
config.filter_parameters << :password
@@ -821,7 +821,7 @@ INFO: _Thanks to clever methods, this is hardly a problem in most Rails applicat
821821

822822
#### Introduction
823823

824-
SQL injection attacks aim at influencing database queries by manipulating web application parameters. A popular goal of SQL injection attacks is to bypass authorization. Another goal is to carry out data manipulation or reading arbitrary data. Here is an example of how not to use user input data in a query:
824+
SQL injection attacks aim at influencing database queries by manipulating web application parameters. A popular goal of SQL injection attacks is to bypass authorization. Another goal is to carry out data manipulation or read arbitrary data. Here is an example of how not to use user input data in a query:
825825

826826
```ruby
827827
Project.where("name = '#{params[:name]}'")
@@ -849,7 +849,7 @@ If an attacker enters `' OR '1'='1` as the name, and `' OR '2'>'1` as the passwo
849849
SELECT * FROM users WHERE login = '' OR '1'='1' AND password = '' OR '2'>'1' LIMIT 1
850850
```
851851

852-
This will simply find the first record in the database, and grants access to this user.
852+
This will simply find the first record in the database and grant access to this user.
853853

854854
#### Unauthorized Reading
855855

@@ -903,7 +903,7 @@ Additionally, you can split and chain conditionals valid for your use case:
903903
Model.where(zip_code: entered_zip_code).where("quantity >= ?", entered_quantity).first
904904
```
905905

906-
Note the previous mentioned countermeasures are only available in model instances. You can
906+
Note that the previously mentioned countermeasures are only available in model instances. You can
907907
try [`sanitize_sql`][] elsewhere. _Make it a habit to think about the security consequences
908908
when using an external string in SQL_.
909909

@@ -921,7 +921,7 @@ The most common entry points are message posts, user comments, and guest books,
921921

922922
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 website to get confidential information or install malicious software through security holes in the web browser.
923923

924-
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 also documented 239 browser plug-in vulnerabilities in the last six months of 2007. [Mpack](https://www.pandasecurity.com/en/mediacenter/malware/mpack-uncovered/) 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 like this, among them the British government, United Nations, and many more high profile targets.
924+
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 also documented 239 browser plug-in vulnerabilities in the last six months of 2007. [Mpack](https://www.pandasecurity.com/en/mediacenter/malware/mpack-uncovered/) 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 like this, among them the British government, United Nations, and many more high-profile targets.
925925

926926
#### HTML/JavaScript Injection
927927

@@ -964,17 +964,17 @@ You can mitigate these attacks (in the obvious way) by adding the **httpOnly** f
964964

965965
##### Defacement
966966

967-
With web page defacement an attacker can do a lot of things, for example, present false information or lure the victim on the attacker's website to steal the cookie, login credentials, or other sensitive data. The most popular way is to include code from external sources by iframes:
967+
With web page defacement, an attacker can do a lot of things, for example, present false information or lure the victim to the attacker's website to steal the cookie, login credentials, or other sensitive data. The most popular way is to include code from external sources by iframes:
968968

969969
```html
970970
<iframe name="StatPage" src="http://58.xx.xxx.xxx" width=5 height=5 style="display:none"></iframe>
971971
```
972972

973973
This loads arbitrary HTML and/or JavaScript from an external source and embeds it as part of the site. This `iframe` is taken from an actual attack on legitimate Italian sites using the [Mpack attack framework](https://isc.sans.edu/diary/MPack+Analysis/3015). Mpack tries to install malicious software through security holes in the web browser - very successfully, 50% of the attacks succeed.
974974

975-
A more specialized attack could overlap the entire website or display a login form, which looks the same as the site's original, but transmits the username and password to the attacker's site. Or it could use CSS and/or JavaScript to hide a legitimate link in the web application, and display another one at its place which redirects to a fake website.
975+
A more specialized attack could overlap the entire website or display a login form, which looks the same as the site's original, but transmits the username and password to the attacker's site. Or it could use CSS and/or JavaScript to hide a legitimate link in the web application, and display another one in its place, which redirects to a fake website.
976976

977-
Reflected injection attacks are those where the payload is not stored to present it to the victim later on, but included in the URL. Especially search forms fail to escape the search string. The following link presented a page which stated that "George Bush appointed a 9 year old boy to be the chairperson...":
977+
Reflected injection attacks are those where the payload is not stored to present it to the victim later on, but is included in the URL. Especially search forms fail to escape the search string. The following link presented a page which stated that "George Bush appointed a 9 year old boy to be the chairperson...":
978978

979979
```
980980
http://www.cbsnews.com/stories/2002/02/15/weather_local/main501644.shtml?zipcode=1-->
@@ -987,7 +987,7 @@ _It is very important to filter malicious input, but it is also important to esc
987987

988988
Especially for XSS, it is important to do _permitted input filtering instead of restricted_. Permitted list filtering states the values allowed as opposed to the values not allowed. Restricted lists are never complete.
989989

990-
Imagine a restricted list deletes `"script"` from the user input. Now the attacker injects `"<scrscriptipt>"`, and after the filter, `"<script>"` remains. Earlier versions of Rails used a restricted list approach for the `strip_tags()`, `strip_links()` and `sanitize()` method. So this kind of injection was possible:
990+
Imagine a restricted list deletes `"script"` from the user input. Now the attacker injects `"<scrscriptipt>"`, and after the filter, `"<script>"` remains. Earlier versions of Rails used a restricted list approach for the `strip_tags()`, `strip_links()`, and `sanitize()` methods. So this kind of injection was possible:
991991

992992
```ruby
993993
strip_tags("some<<b>script>alert('hello')<</b>/script>")
@@ -1015,7 +1015,7 @@ Network traffic is mostly based on the limited Western alphabet, so new characte
10151015
&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>
10161016
```
10171017

1018-
This example pops up a message box. It will be recognized by the above `sanitize()` filter, though. A great tool to obfuscate and encode strings, and thus "get to know your enemy", is the [Hackvertor](https://hackvertor.co.uk/public). Rails' `sanitize()` method does a good job to fend off encoding attacks.
1018+
This example pops up a message box. It will be recognized by the above `sanitize()` filter, though. A great tool to obfuscate and encode strings, and thus "get to know your enemy", is the [Hackvertor](https://hackvertor.co.uk/). Rails' `sanitize()` method does a good job to fend off encoding attacks.
10191019

10201020
#### Examples from the Underground
10211021

@@ -1033,7 +1033,7 @@ The worms exploit a hole in Yahoo's HTML/JavaScript filter, which usually filter
10331033
10341034
Another proof-of-concept webmail worm is Nduja, a cross-domain worm for four Italian webmail services. Find more details on [Rosario Valotta's paper](http://www.xssed.com/news/37/Nduja_Connection_A_cross_webmail_worm_XWW/). Both webmail worms have the goal to harvest email addresses, something a criminal hacker could make money with.
10351035
1036-
In December 2006, 34,000 actual usernames and passwords were stolen in a [MySpace phishing attack](https://news.netcraft.com/archives/2006/10/27/myspace_accounts_compromised_by_phishers.html). The idea of the attack was to create a profile page named "login_home_index_html", so the URL looked very convincing. Specially-crafted HTML and CSS was used to hide the genuine MySpace content from the page and instead display its own login form.
1036+
In December 2006, 34,000 actual usernames and passwords were stolen in a [MySpace phishing attack](https://www.schneier.com/essays/archives/2006/12/myspace_passwords_ar.html). The idea of the attack was to create a profile page named "login_home_index_html", so the URL looked very convincing. Specially-crafted HTML and CSS were used to hide the genuine MySpace content from the page and instead display its own login form.
10371037
10381038
### CSS Injection
10391039

0 commit comments

Comments
 (0)