safe_cookies 0.1.7 → 0.2.0
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.
- checksums.yaml +8 -8
- data/README.md +16 -13
- data/lib/safe_cookies/version.rb +1 -1
- data/lib/safe_cookies.rb +10 -4
- data/spec/safe_cookies_spec.rb +17 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjY2ZmQ0ZDEzMWVhMDRmNWE0MmM2ODRjYTU5MzEyZmQxN2JkMGQzMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2E2Yzg5OGQzMzkyYWI3N2E1MWJlZWJmZjI1NGM0ZjY2MjkzNDVkZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzU1ZTQyYjQzNmNhNzljNzA2Y2U2NWIyMDU5MTkyMTU5MDZjYmQ0ZDY4MjNl
|
10
|
+
M2MxMWJhYmQwMzJkZDdlYzJlZTkwYWFkNWJkNzE4ZTc5MTUxOWI0YjMwNmVk
|
11
|
+
NGM0YzUyZWU3MjJjMGZlMzgzYjk2OTg4OWU1MzY5ZGQzYjE0NzE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTMzYTYzN2JkMzk3OGU5NzE4MzAwMWUxYWVmMmI1ZThmYTExNmQyNzgyYWU4
|
14
|
+
YjFiYzIyOTg4YTk0Njg3YTk0NzRiMjAyMzc1NmM0OWVhYjRhNWI3NDdlZjZm
|
15
|
+
NTMxYTkwNmJlYTJlMjBkY2NhMGYzM2MwYzRkYzcwMTViMTlmMzc=
|
data/README.md
CHANGED
@@ -66,19 +66,22 @@ The middleware is not able to secure cookies without knowing their attributes
|
|
66
66
|
if it stores the cookie with flags such as "secure" or which expiry date it
|
67
67
|
currently has. Therefore, it is important to register all cookies that may be
|
68
68
|
sent by the client, specifying their properties. Unregistered cookies cannot be
|
69
|
-
secured.
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
69
|
+
secured by the middleware.
|
70
|
+
|
71
|
+
Unknown cookies are written to the Rails log. When you start implementing the
|
72
|
+
middleware, you should closely watch it to find cookies you forgot to register.
|
73
|
+
You may overwrite `SafeCookies::Middleware#handle_unknown_cookies(cookies)` in
|
74
|
+
the config initializer for customized behaviour (like, notifying you per email).
|
75
|
+
|
76
|
+
You should register any cookie that your application is using.
|
77
|
+
|
78
|
+
|
79
|
+
## Ignoring cookies
|
80
|
+
|
81
|
+
Currently, ignoring cookies only prevents the middleware from writing them to the logs.
|
82
|
+
|
83
|
+
You can tell the middleware to ignore cookies with the `config.ignore_cookie`
|
84
|
+
directive, which takes either a String or a Regex parameter. Be careful when using regular expressions!
|
82
85
|
|
83
86
|
|
84
87
|
## Fix cookie paths
|
data/lib/safe_cookies/version.rb
CHANGED
data/lib/safe_cookies.rb
CHANGED
@@ -18,6 +18,7 @@ module SafeCookies
|
|
18
18
|
STORE_COOKIE_NAME = '_safe_cookies__known_cookies'
|
19
19
|
SECURED_COOKIE_NAME = 'secured_old_cookies'
|
20
20
|
HELPER_COOKIES_LIFETIME = 10 * 365 * 24 * 60 * 60 # 10 years
|
21
|
+
|
21
22
|
|
22
23
|
class Middleware
|
23
24
|
|
@@ -57,9 +58,7 @@ module SafeCookies
|
|
57
58
|
def reset_instance_variables
|
58
59
|
@request, @headers, @application_cookies_string = nil
|
59
60
|
end
|
60
|
-
|
61
|
-
# Do something if a request has an unregistered cookie, because we do not
|
62
|
-
# want any cookie to not be secured. By default, we raise an error.
|
61
|
+
|
63
62
|
def check_if_request_has_unknown_cookies
|
64
63
|
request_cookie_names = request_cookies.keys.map(&:to_s)
|
65
64
|
unknown_cookie_names = request_cookie_names - known_cookie_names
|
@@ -129,7 +128,14 @@ module SafeCookies
|
|
129
128
|
|
130
129
|
# API method
|
131
130
|
def handle_unknown_cookies(cookie_names)
|
132
|
-
|
131
|
+
log_error("Request for '#{@request.url}' had unknown cookies: #{cookie_names.join(', ')}")
|
132
|
+
end
|
133
|
+
|
134
|
+
def log_error(error_message)
|
135
|
+
message = '** [SafeCookies error] '
|
136
|
+
message << error_message
|
137
|
+
|
138
|
+
Rails.logger.error(message) if defined?(Rails)
|
133
139
|
end
|
134
140
|
|
135
141
|
end
|
data/spec/safe_cookies_spec.rb
CHANGED
@@ -207,16 +207,22 @@ describe SafeCookies::Middleware do
|
|
207
207
|
end
|
208
208
|
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
|
+
|
212
|
+
# The unknown cookies mechanism was more important when we were sending
|
213
|
+
# notifications on encountering unknown cookies. Perhaps, it will regain
|
214
|
+
# importance in the future.
|
211
215
|
context 'when a request has unknown cookies,' do
|
212
216
|
|
213
|
-
it '
|
217
|
+
it 'logs an error message' do
|
218
|
+
stub_app_call(app)
|
214
219
|
set_request_cookies(env, 'foo=bar')
|
215
|
-
|
216
|
-
|
220
|
+
|
221
|
+
subject.should_receive(:log_error).with(/unknown cookies: foo/)
|
222
|
+
subject.call(env)
|
217
223
|
end
|
218
224
|
|
219
|
-
it 'does not
|
225
|
+
it 'does not log an error if the (unregistered) cookie was initially set by the application' do
|
220
226
|
# application sets cookie
|
221
227
|
stub_app_call(app, :application_cookies => 'foo=bar; path=/some/path; secure')
|
222
228
|
|
@@ -233,10 +239,11 @@ describe SafeCookies::Middleware do
|
|
233
239
|
stub_app_call(other_app)
|
234
240
|
set_request_cookies(env, *received_cookies)
|
235
241
|
|
242
|
+
other_subject.should_not_receive(:log_error)
|
236
243
|
other_subject.call(env)
|
237
244
|
end
|
238
245
|
|
239
|
-
it 'does not
|
246
|
+
it 'does not log an error if the cookie is listed in the cookie configuration' do
|
240
247
|
SafeCookies.configure do |config|
|
241
248
|
config.register_cookie('foo', :expire_after => 3600)
|
242
249
|
end
|
@@ -244,10 +251,11 @@ describe SafeCookies::Middleware do
|
|
244
251
|
stub_app_call(app)
|
245
252
|
set_request_cookies(env, 'foo=bar')
|
246
253
|
|
254
|
+
subject.should_not_receive(:log_error)
|
247
255
|
subject.call(env)
|
248
256
|
end
|
249
257
|
|
250
|
-
it 'does not
|
258
|
+
it 'does not log an error if the cookie is ignored' do
|
251
259
|
SafeCookies.configure do |config|
|
252
260
|
config.ignore_cookie '__utma'
|
253
261
|
end
|
@@ -255,10 +263,11 @@ describe SafeCookies::Middleware do
|
|
255
263
|
stub_app_call(app)
|
256
264
|
set_request_cookies(env, '__utma=tracking')
|
257
265
|
|
266
|
+
subject.should_not_receive(:log_error)
|
258
267
|
subject.call(env)
|
259
268
|
end
|
260
269
|
|
261
|
-
it 'allows overwriting the
|
270
|
+
it 'allows overwriting the handling mechanism' do
|
262
271
|
stub_app_call(app)
|
263
272
|
set_request_cookies(env, 'foo=bar')
|
264
273
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safe_cookies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Schöler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.1.
|
112
|
+
rubygems_version: 2.1.3
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Make all cookies `secure` and `HttpOnly`.
|