breach-mitigation-rails 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rspec +1 -0
- data/README.md +0 -6
- data/breach-mitigation-rails.gemspec +1 -0
- data/lib/breach_mitigation/length_hiding.rb +2 -2
- data/lib/breach_mitigation/masking_secrets.rb +5 -1
- data/lib/breach_mitigation/railtie.rb +1 -1
- data/lib/breach_mitigation/version.rb +1 -1
- data/spec/length_hiding_spec.rb +17 -0
- data/spec/spec_helper.rb +16 -0
- metadata +24 -3
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/README.md
CHANGED
@@ -22,12 +22,6 @@ prevent plaintext recovery, but it can slow the attack and it's
|
|
22
22
|
relatively inexpensive to implement. Unlike the CSRF token masking,
|
23
23
|
length hiding protects the entire page body from recovery.
|
24
24
|
|
25
|
-
In addition to these mitigations, you should check out Twitter's
|
26
|
-
[secure_headers](https://github.com/twitter/secureheaders) gem.
|
27
|
-
Setting the X-Frame-Options header can make it harder for an attacker
|
28
|
-
to carry out this attack (by making it impossible to put your site in
|
29
|
-
an iframe).
|
30
|
-
|
31
25
|
## Warning!
|
32
26
|
|
33
27
|
BREACH and CRIME are **complicated and wide-ranging attacks**, and this
|
@@ -39,9 +39,9 @@ module BreachMitigation
|
|
39
39
|
# data itself doesn't need to be strongly random; it just needs
|
40
40
|
# to be resistant to compression
|
41
41
|
length = SecureRandom.random_number(MAX_LENGTH)
|
42
|
-
junk =
|
42
|
+
junk = (0...length).inject("") { |junk| junk << ALPHABET[rand(ALPHABET.size)] }
|
43
43
|
|
44
|
-
"\n<!-- This is a random-length HTML comment: #{junk} -->"
|
44
|
+
"\n<!-- This is a random-length HTML comment: #{junk} -->".html_safe
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -19,7 +19,11 @@ module BreachMitigation
|
|
19
19
|
def valid_authenticity_token?(session, encoded_masked_token)
|
20
20
|
return false if encoded_masked_token.nil? || encoded_masked_token.empty?
|
21
21
|
|
22
|
-
|
22
|
+
begin
|
23
|
+
masked_token = Base64.strict_decode64(encoded_masked_token)
|
24
|
+
rescue ArgumentError # encoded_masked_token is invalid Base64
|
25
|
+
return false
|
26
|
+
end
|
23
27
|
|
24
28
|
# See if it's actually a masked token or not. In order to
|
25
29
|
# deploy this code, we should be able to handle any unmasked
|
@@ -4,7 +4,7 @@ require 'breach_mitigation/masking_secrets'
|
|
4
4
|
module BreachMitigation
|
5
5
|
class Railtie < Rails::Railtie
|
6
6
|
initializer "breach-mitigation-rails.insert_middleware" do |app|
|
7
|
-
app.config.middleware.
|
7
|
+
app.config.middleware.insert_before 'Rack::ETag', "BreachMitigation::LengthHiding"
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "breach_mitigation/length_hiding"
|
3
|
+
|
4
|
+
describe BreachMitigation::LengthHiding do
|
5
|
+
let(:length_hiding) { BreachMitigation::LengthHiding.new(double()) }
|
6
|
+
|
7
|
+
describe "#random_html_comment" do
|
8
|
+
it "should have different lengths on different runs" do
|
9
|
+
lengths = []
|
10
|
+
10.times do
|
11
|
+
random_comment = length_hiding.send(:random_html_comment)
|
12
|
+
lengths << random_comment.size
|
13
|
+
end
|
14
|
+
lengths.uniq.size.should > 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'breach-mitigation-rails'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
config.filter_run :focus
|
10
|
+
|
11
|
+
# Run specs in random order to surface order dependencies. If you find an
|
12
|
+
# order dependency and want to debug it, you can fix the order by providing
|
13
|
+
# the seed, which is printed after each run.
|
14
|
+
# --seed 1234
|
15
|
+
config.order = 'random'
|
16
|
+
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: breach-mitigation-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Bradley Buda
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '1.3'
|
29
29
|
none: false
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
none: false
|
37
|
+
name: rspec
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
none: false
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
version_requirements: !ruby/object:Gem::Requirement
|
32
48
|
requirements:
|
@@ -51,6 +67,7 @@ extensions: []
|
|
51
67
|
extra_rdoc_files: []
|
52
68
|
files:
|
53
69
|
- .gitignore
|
70
|
+
- .rspec
|
54
71
|
- Gemfile
|
55
72
|
- LICENSE.txt
|
56
73
|
- README.md
|
@@ -61,6 +78,8 @@ files:
|
|
61
78
|
- lib/breach_mitigation/masking_secrets.rb
|
62
79
|
- lib/breach_mitigation/railtie.rb
|
63
80
|
- lib/breach_mitigation/version.rb
|
81
|
+
- spec/length_hiding_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
64
83
|
homepage: https://github.com/meldium/breach-mitigation-rails
|
65
84
|
licenses:
|
66
85
|
- MIT
|
@@ -87,5 +106,7 @@ signing_key:
|
|
87
106
|
specification_version: 3
|
88
107
|
summary: Uses length-hiding and CSRF token masking to make it more difficult for an
|
89
108
|
attacker to recover plaintext from HTTP responses. See README.md for details.
|
90
|
-
test_files:
|
109
|
+
test_files:
|
110
|
+
- spec/length_hiding_spec.rb
|
111
|
+
- spec/spec_helper.rb
|
91
112
|
has_rdoc:
|