Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
test: Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rtfpessoa committed May 24, 2020
1 parent cf6ebe0 commit 1002c37
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions spec/yavdb/sources/snyk_io/client_spec.rb
Expand Up @@ -125,7 +125,7 @@
expect(vuln).to have_attributes(:title => 'Authorization Bypass')
expect(vuln).to have_attributes(:description => "[`sorcery`][1] Provides common authentication needs such as signing\nin/out, activating by email and resetting password.\n\nAffected versions of the package are vulnerable to Authorization Bypass.\nThe `state` field was kept between requests.\n\n\n\n[1]: https://rubygems.org/gems/sorcery\n")
expect(vuln).to have_attributes(:affected_package => 'sorcery')
expect(vuln).to have_attributes(:vulnerable_versions => ['<0.9.1 >=0.8.3'])
expect(vuln).to have_attributes(:vulnerable_versions => ['>=0.8.3 <0.9.1'])
expect(vuln).to have_attributes(:severity => 'low')
expect(vuln).to have_attributes(:package_manager => 'rubygems')
expect(vuln).to have_attributes(:cve => nil)
Expand Down Expand Up @@ -197,7 +197,7 @@
expect(vuln).to have_attributes(:title => 'Regular Expression Denial of Service (ReDoS)')
expect(vuln).to have_attributes(:description => "[`mime`][1] is a comprehensive, compact MIME type module.\n\nAffected versions of this package are vulnerable to Regular expression\nDenial of Service (ReDoS). It uses regex the following regex\n`/.*[\\.\\/\\\\]/` in its lookup, which can cause a slowdown of 2 seconds\nfor 50k characters.\n\n\n\n[1]: https://www.npmjs.com/package/mime\n\\nDenial of Service (DoS) describes a family of attacks, all aimed at\nmaking a system inaccessible to its original and legitimate users. There\nare many types of DoS attacks, ranging from trying to clog the network\npipes to the system by generating a large volume of traffic from many\nmachines (a Distributed Denial of Service - DDoS - attack) to sending\ncrafted requests that cause a system to crash or take a disproportional\namount of time to process.\n\nThe Regular expression Denial of Service (ReDoS) is a type of Denial of\nService attack. Regular expressions are incredibly powerful, but they\naren\\'t very intuitive and can ultimately end up making it easy for\nattackers to take your site down.\n\nLet’s take the following regular expression as an example:\n\n regex = /A(B|C+)+D/\n{: .language-js}\n\nThis regular expression accomplishes the following:\n\n* `A` The string must start with the letter \\'A\\'\n* `(B|C+)+` The string must then follow the letter A with either the\n letter \\'B\\' or some number of occurrences of the letter \\'C\\' (the\n `+` matches one or more times). The `+` at the end of this section\n states that we can look for one or more matches of this section.\n* `D` Finally, we ensure this section of the string ends with a \\'D\\'\n\nThe expression would match inputs such as `ABBD`, `ABCCCCD`, `ABCBCCCD`\nand `ACCCCCD`\n\nIt most cases, it doesn\\'t take very long for a regex engine to find a\nmatch:\n\n $ time node -e '/A(B|C+)+D/.test(\"ACCCCCCCCCCCCCCCCCCCCCCCCCCCCD\")'\n 0.04s user 0.01s system 95% cpu 0.052 total\n \n $ time node -e '/A(B|C+)+D/.test(\"ACCCCCCCCCCCCCCCCCCCCCCCCCCCCX\")'\n 1.79s user 0.02s system 99% cpu 1.812 total\n{: .language-bash}\n\nThe entire process of testing it against a 30 characters long string\ntakes around ~52ms. But when given an invalid string, it takes nearly\ntwo seconds to complete the test, over ten times as long as it took to\ntest a valid string. The dramatic difference is due to the way regular\nexpressions get evaluated.\n\nMost Regex engines will work very similarly (with minor differences).\nThe engine will match the first possible way to accept the current\ncharacter and proceed to the next one. If it then fails to match the\nnext one, it will backtrack and see if there was another way to digest\nthe previous character. If it goes too far down the rabbit hole only to\nfind out the string doesn’t match in the end, and if many characters\nhave multiple valid regex paths, the number of backtracking steps can\nbecome very large, resulting in what is known as *catastrophic\nbacktracking*.\n\nLet\\'s look at how our expression runs into this problem, using a\nshorter string: \\\"ACCCX\\\". While it seems fairly straightforward, there\nare still four different ways that the engine could match those three\nC\\'s:\n\n1. CCC\n2. CC+C\n3. C+CC\n4. C+C+C.\n\nThe engine has to try each of those combinations to see if any of them\npotentially match against the expression. When you combine that with the\nother steps the engine must take, we can use [RegEx 101 debugger][1] to\nsee the engine has to take a total of 38 steps before it can determine\nthe string doesn\\'t match.\n\nFrom there, the number of steps the engine must use to validate a string\njust continues to grow.\n\n| String | Number of C\\'s | Number of steps |\n|----------\n| ACCCX | 3 | 38 |\n| ACCCCX | 4 | 71 |\n| ACCCCCX | 5 | 136 |\n| ACCCCCCCCCCCCCCX | 14 | 65,553 |\n\nBy the time the string includes 14 C\\'s, the engine has to take over\n65,000 steps just to see if the string is valid. These extreme\nsituations can cause them to work very slowly (exponentially related to\ninput size, as shown above), allowing an attacker to exploit this and\ncan cause the service to excessively consume CPU, resulting in a Denial\nof Service.\n\n\n\n[1]: https://regex101.com/debugger\n")
expect(vuln).to have_attributes(:affected_package => 'mime')
expect(vuln).to have_attributes(:vulnerable_versions => ['[,1.4.1), [2,2.0.3)'])
expect(vuln).to have_attributes(:vulnerable_versions => ['[,1.4.1) || [2,2.0.3)'])
expect(vuln).to have_attributes(:severity => 'low')
expect(vuln).to have_attributes(:package_manager => 'nuget')
expect(vuln).to have_attributes(:cve => nil)
Expand Down

0 comments on commit 1002c37

Please sign in to comment.