rack-cors-csrf_prevention 0.2.1 → 0.3.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 +4 -4
- data/.rubocop.yml +9 -2
- data/Gemfile.lock +32 -1
- data/README.md +27 -8
- data/lib/rack/cors/csrf_prevention/version.rb +1 -1
- data/lib/rack/cors/csrf_prevention.rb +8 -2
- data/rack-cors-csrf_prevention.gemspec +3 -1
- metadata +29 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f58e017a9570b557ee1c4028c57d65790e63033ac89e8fd60e9b040286397c7b
|
|
4
|
+
data.tar.gz: e8e76479edd2eb9eaad26cf64e64ae538241483595910b4411bf0193c9f6f956
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9c5d439ce879f6e557015e064b5ee2467ec65eef82a742834b013f342390fd34b38d2c5dbe3a7d9b49a1eab0862de1360589b7fab3910b91c3ccabce2e8af2c8
|
|
7
|
+
data.tar.gz: 6d5b5076c5c65cb4e8c853a30b2d2ac18d5ebc2c68b3e3872912e85612ba7db3c26c9320350be30fcbfd1001aeb8b0fb50ec2be7bca4a45324b8e403546d23c0
|
data/.rubocop.yml
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
AllCops:
|
|
2
2
|
NewCops: enable
|
|
3
|
+
Exclude:
|
|
4
|
+
- "bin/bundle"
|
|
5
|
+
|
|
6
|
+
Gemspec/DevelopmentDependencies:
|
|
7
|
+
EnforcedStyle: gemspec
|
|
3
8
|
|
|
4
9
|
Metrics/BlockLength:
|
|
5
|
-
|
|
6
|
-
- *.gemspec
|
|
10
|
+
Enabled: false
|
|
7
11
|
|
|
8
12
|
Metrics/ParameterLists:
|
|
9
13
|
CountKeywordArgs: false
|
|
10
14
|
|
|
15
|
+
Style/Documentation:
|
|
16
|
+
Enabled: false
|
|
17
|
+
|
|
11
18
|
Style/StringLiterals:
|
|
12
19
|
EnforcedStyle: double_quotes
|
data/Gemfile.lock
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rack-cors-csrf_prevention (0.
|
|
4
|
+
rack-cors-csrf_prevention (0.3.0)
|
|
5
5
|
rack (>= 1)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
+
ast (2.4.3)
|
|
10
11
|
debug (1.9.1)
|
|
11
12
|
irb (~> 1.10)
|
|
12
13
|
reline (>= 0.3.8)
|
|
@@ -15,12 +16,23 @@ GEM
|
|
|
15
16
|
irb (1.11.2)
|
|
16
17
|
rdoc
|
|
17
18
|
reline (>= 0.4.2)
|
|
19
|
+
json (2.16.0)
|
|
20
|
+
language_server-protocol (3.17.0.5)
|
|
21
|
+
lint_roller (1.1.0)
|
|
22
|
+
parallel (1.27.0)
|
|
23
|
+
parser (3.3.10.0)
|
|
24
|
+
ast (~> 2.4.1)
|
|
25
|
+
racc
|
|
26
|
+
prism (1.6.0)
|
|
18
27
|
psych (5.1.2)
|
|
19
28
|
stringio
|
|
29
|
+
racc (1.8.1)
|
|
20
30
|
rack (2.2.7)
|
|
31
|
+
rainbow (3.1.1)
|
|
21
32
|
rake (13.0.6)
|
|
22
33
|
rdoc (6.6.2)
|
|
23
34
|
psych (>= 4.0.0)
|
|
35
|
+
regexp_parser (2.11.3)
|
|
24
36
|
reline (0.4.2)
|
|
25
37
|
io-console (~> 0.5)
|
|
26
38
|
rspec (3.12.0)
|
|
@@ -36,7 +48,25 @@ GEM
|
|
|
36
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
37
49
|
rspec-support (~> 3.12.0)
|
|
38
50
|
rspec-support (3.12.0)
|
|
51
|
+
rubocop (1.81.7)
|
|
52
|
+
json (~> 2.3)
|
|
53
|
+
language_server-protocol (~> 3.17.0.2)
|
|
54
|
+
lint_roller (~> 1.1.0)
|
|
55
|
+
parallel (~> 1.10)
|
|
56
|
+
parser (>= 3.3.0.2)
|
|
57
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
58
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
59
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
60
|
+
ruby-progressbar (~> 1.7)
|
|
61
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
62
|
+
rubocop-ast (1.48.0)
|
|
63
|
+
parser (>= 3.3.7.2)
|
|
64
|
+
prism (~> 1.4)
|
|
65
|
+
ruby-progressbar (1.13.0)
|
|
39
66
|
stringio (3.1.0)
|
|
67
|
+
unicode-display_width (3.2.0)
|
|
68
|
+
unicode-emoji (~> 4.1)
|
|
69
|
+
unicode-emoji (4.1.0)
|
|
40
70
|
|
|
41
71
|
PLATFORMS
|
|
42
72
|
arm64-darwin-22
|
|
@@ -47,6 +77,7 @@ DEPENDENCIES
|
|
|
47
77
|
rack-cors-csrf_prevention!
|
|
48
78
|
rake (~> 13.0)
|
|
49
79
|
rspec (~> 3.0)
|
|
80
|
+
rubocop (~> 1.81, >= 1.81.1)
|
|
50
81
|
|
|
51
82
|
BUNDLED WITH
|
|
52
83
|
2.4.4
|
data/README.md
CHANGED
|
@@ -26,27 +26,46 @@ gem install rack-cors-csrf_prevention
|
|
|
26
26
|
Rails.application.config.middleware.use Rack::Cors::CsrfPrevention
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
#### Paths
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
By default, the gem protects only `/graphql` path.
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
# config/initializers/cors.rb
|
|
33
|
+
You can set your path using `path` argument:
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
required_headers: %w[SOME-SPECIAL-HEADER]
|
|
35
|
+
```ruby
|
|
36
|
+
config.middleware.use Rack::Cors::CsrfPrevention, path: "/gql"
|
|
39
37
|
```
|
|
40
38
|
|
|
41
39
|
Also, you can configure multiple paths via `paths` argument.
|
|
42
40
|
|
|
41
|
+
#### Headers
|
|
42
|
+
|
|
43
|
+
By default, gem allows only `X-Apollo-Operation-Name` or `Apollo-Require-Preflight` header for non-preflighted content types.
|
|
44
|
+
|
|
45
|
+
You can add additional headers for CSRF prevention:
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
config.middleware.use Rack::Cors::CsrfPrevention,
|
|
49
|
+
required_headers: %w[SOME-SPECIAL-HEADER]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Error message
|
|
53
|
+
|
|
54
|
+
By default, gem returns detailed error message that can help API clients in development.
|
|
55
|
+
|
|
56
|
+
You can hide detailed error message in a production environment:
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
config.middleware.use Rack::Cors::CsrfPrevention, detailed_error: !Rails.env.production?
|
|
60
|
+
```
|
|
61
|
+
|
|
43
62
|
## Development
|
|
44
63
|
|
|
45
64
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
46
65
|
`bin/rake spec` to run the tests. You can also run `bin/console` for an
|
|
47
66
|
interactive prompt that will allow you to experiment.
|
|
48
67
|
|
|
49
|
-
To install this gem onto your local machine, run `bin/rake
|
|
68
|
+
To install this gem onto your local machine, run `bin/rake install`.
|
|
50
69
|
To release a new version, update the version number in `version.rb`, and then
|
|
51
70
|
run `bin/rake release`, which will create a git tag for the version,
|
|
52
71
|
push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
@@ -30,11 +30,13 @@ module Rack
|
|
|
30
30
|
app,
|
|
31
31
|
path: nil,
|
|
32
32
|
paths: [],
|
|
33
|
-
required_headers: []
|
|
33
|
+
required_headers: [],
|
|
34
|
+
detailed_error: true
|
|
34
35
|
)
|
|
35
36
|
@app = app
|
|
36
37
|
@paths = path.nil? && paths.empty? ? ["/graphql"] : [path].compact + paths
|
|
37
38
|
@required_headers = APOLLO_CUSTOM_PREFLIGHT_HEADERS + required_headers
|
|
39
|
+
@detailed_error = detailed_error
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
def call(env)
|
|
@@ -49,7 +51,7 @@ module Rack
|
|
|
49
51
|
else
|
|
50
52
|
logger(env).debug { "Request isn't preflighted" }
|
|
51
53
|
|
|
52
|
-
Rack::Response[400, { "Content-Type" => "text/plain" },
|
|
54
|
+
Rack::Response[400, { "Content-Type" => "text/plain" }, response_body].to_a
|
|
53
55
|
end
|
|
54
56
|
end
|
|
55
57
|
|
|
@@ -72,6 +74,10 @@ module Rack
|
|
|
72
74
|
def recommended_header_provided?(request)
|
|
73
75
|
@required_headers.any? { |header| request.has_header?("HTTP_#{header}") }
|
|
74
76
|
end
|
|
77
|
+
|
|
78
|
+
def response_body
|
|
79
|
+
@detailed_error ? ERROR_MESSAGE : "Bad Request"
|
|
80
|
+
end
|
|
75
81
|
end
|
|
76
82
|
end
|
|
77
83
|
end
|
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
|
|
|
37
37
|
spec.required_ruby_version = ">= 2.6.0"
|
|
38
38
|
|
|
39
39
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
40
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
40
41
|
spec.metadata["source_code_uri"] = spec.homepage
|
|
41
42
|
|
|
42
43
|
# Specify which files should be added to the gem when it is released.
|
|
@@ -50,7 +51,8 @@ Gem::Specification.new do |spec|
|
|
|
50
51
|
|
|
51
52
|
spec.add_dependency "rack", ">= 1"
|
|
52
53
|
|
|
54
|
+
spec.add_development_dependency "debug", "~> 1.9", ">= 1.9.1"
|
|
53
55
|
spec.add_development_dependency "rake", "~> 13.0"
|
|
54
56
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
55
|
-
spec.add_development_dependency "
|
|
57
|
+
spec.add_development_dependency "rubocop", "~> 1.81", ">= 1.81.1"
|
|
56
58
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rack-cors-csrf_prevention
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Digital Classifieds LLC
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rack
|
|
@@ -24,6 +23,26 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: debug
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '1.9'
|
|
33
|
+
- - ">="
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: 1.9.1
|
|
36
|
+
type: :development
|
|
37
|
+
prerelease: false
|
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - "~>"
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '1.9'
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 1.9.1
|
|
27
46
|
- !ruby/object:Gem::Dependency
|
|
28
47
|
name: rake
|
|
29
48
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -53,25 +72,25 @@ dependencies:
|
|
|
53
72
|
- !ruby/object:Gem::Version
|
|
54
73
|
version: '3.0'
|
|
55
74
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
75
|
+
name: rubocop
|
|
57
76
|
requirement: !ruby/object:Gem::Requirement
|
|
58
77
|
requirements:
|
|
59
78
|
- - "~>"
|
|
60
79
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '1.
|
|
80
|
+
version: '1.81'
|
|
62
81
|
- - ">="
|
|
63
82
|
- !ruby/object:Gem::Version
|
|
64
|
-
version: 1.
|
|
83
|
+
version: 1.81.1
|
|
65
84
|
type: :development
|
|
66
85
|
prerelease: false
|
|
67
86
|
version_requirements: !ruby/object:Gem::Requirement
|
|
68
87
|
requirements:
|
|
69
88
|
- - "~>"
|
|
70
89
|
- !ruby/object:Gem::Version
|
|
71
|
-
version: '1.
|
|
90
|
+
version: '1.81'
|
|
72
91
|
- - ">="
|
|
73
92
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: 1.
|
|
93
|
+
version: 1.81.1
|
|
75
94
|
description: |
|
|
76
95
|
The middleware makes sure any request to specified paths would have been
|
|
77
96
|
preflighted if it was sent by a browser.
|
|
@@ -95,7 +114,6 @@ description: |
|
|
|
95
114
|
headers to be set. By ensuring that every operation either has a custom
|
|
96
115
|
content-type or sets one of these headers, we know we won't execute
|
|
97
116
|
operations at the request of origins who our CORS policy will block.
|
|
98
|
-
email:
|
|
99
117
|
executables: []
|
|
100
118
|
extensions: []
|
|
101
119
|
extra_rdoc_files: []
|
|
@@ -115,8 +133,8 @@ licenses:
|
|
|
115
133
|
- MIT
|
|
116
134
|
metadata:
|
|
117
135
|
homepage_uri: https://github.com/digitaz/rack-cors-csrf_prevention
|
|
136
|
+
rubygems_mfa_required: 'true'
|
|
118
137
|
source_code_uri: https://github.com/digitaz/rack-cors-csrf_prevention
|
|
119
|
-
post_install_message:
|
|
120
138
|
rdoc_options: []
|
|
121
139
|
require_paths:
|
|
122
140
|
- lib
|
|
@@ -131,8 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
131
149
|
- !ruby/object:Gem::Version
|
|
132
150
|
version: '0'
|
|
133
151
|
requirements: []
|
|
134
|
-
rubygems_version: 3.
|
|
135
|
-
signing_key:
|
|
152
|
+
rubygems_version: 3.6.7
|
|
136
153
|
specification_version: 4
|
|
137
154
|
summary: Ruby implementation of CSRF prevention from the Apollo Router.
|
|
138
155
|
test_files: []
|