zantetsuken 0.1.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 +7 -0
- data/.github/workflows/gem-push.yml +42 -0
- data/.github/workflows/main.yml +23 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +109 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +8 -0
- data/bin/console +20 -0
- data/bin/setup +8 -0
- data/lib/zantetsuken.rb +20 -0
- data/lib/zantetsuken/ruleset.rb +26 -0
- data/lib/zantetsuken/ruleset/base.rb +55 -0
- data/lib/zantetsuken/version.rb +5 -0
- data/zantetsuken.gemspec +36 -0
- metadata +161 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f5397228c0d640dee4b610227035a22677d2172b3fd0ab1b01396c980ccd4712
|
|
4
|
+
data.tar.gz: beff85239f89101a48db8b4cdd683932660205ba0412b0aa59554e28a0dfd964
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '08fe73bfdf6b09dad2a371ea32939b679162fa05b3a000c6dabe98b93487a5002fb234d2cceab7147eb255578f35d389ea8f9b387bce3f495155adabbde5c12b'
|
|
7
|
+
data.tar.gz: 02f0cbd7849794c2d29b5cba9a6b073a0fb90cdaaa7e2095bcc3dd9c58e06dec630a6b3fcef63725486058b8331a23d2dc5d03451f7ad91035b18d86ae2e32ad
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: Ruby Gem
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
paths:
|
|
7
|
+
- 'lib/zantetsuken/version.rb'
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
name: Build + Publish
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v2
|
|
16
|
+
- name: Set up Ruby 2.7
|
|
17
|
+
uses: actions/setup-ruby@v1
|
|
18
|
+
with:
|
|
19
|
+
ruby-version: 2.7.x
|
|
20
|
+
|
|
21
|
+
- name: Publish to GPR
|
|
22
|
+
run: |
|
|
23
|
+
mkdir -p $HOME/.gem
|
|
24
|
+
touch $HOME/.gem/credentials
|
|
25
|
+
chmod 0600 $HOME/.gem/credentials
|
|
26
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
|
27
|
+
gem build *.gemspec
|
|
28
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
|
29
|
+
env:
|
|
30
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
|
31
|
+
OWNER: ${{ github.repository_owner }}
|
|
32
|
+
|
|
33
|
+
- name: Publish to RubyGems
|
|
34
|
+
run: |
|
|
35
|
+
mkdir -p $HOME/.gem
|
|
36
|
+
touch $HOME/.gem/credentials
|
|
37
|
+
chmod 0600 $HOME/.gem/credentials
|
|
38
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
|
39
|
+
gem build *.gemspec
|
|
40
|
+
gem push *.gem
|
|
41
|
+
env:
|
|
42
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: CSP Builder
|
|
2
|
+
on: push
|
|
3
|
+
|
|
4
|
+
jobs:
|
|
5
|
+
verify:
|
|
6
|
+
name: Build
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v1
|
|
10
|
+
- name: Set up Ruby
|
|
11
|
+
uses: actions/setup-ruby@v1
|
|
12
|
+
with:
|
|
13
|
+
ruby-version: 2.7.x
|
|
14
|
+
- name: Install dependencies
|
|
15
|
+
run: |
|
|
16
|
+
sudo apt-get update
|
|
17
|
+
sudo apt-get -yqq install libpq-dev build-essential libcurl4-openssl-dev
|
|
18
|
+
gem install bundler
|
|
19
|
+
bundle install --jobs 4 --retry 3
|
|
20
|
+
- name: Lint
|
|
21
|
+
run: rubocop
|
|
22
|
+
- name: Run tests
|
|
23
|
+
run: rspec
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
|
File without changes
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at si@mon.fish. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
zantetsuken (0.1.0)
|
|
5
|
+
actionpack (~> 6.1.4, >= 6.0.0)
|
|
6
|
+
activemodel (~> 6.1.4, >= 6.0.0)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
actionpack (6.1.4)
|
|
12
|
+
actionview (= 6.1.4)
|
|
13
|
+
activesupport (= 6.1.4)
|
|
14
|
+
rack (~> 2.0, >= 2.0.9)
|
|
15
|
+
rack-test (>= 0.6.3)
|
|
16
|
+
rails-dom-testing (~> 2.0)
|
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
18
|
+
actionview (6.1.4)
|
|
19
|
+
activesupport (= 6.1.4)
|
|
20
|
+
builder (~> 3.1)
|
|
21
|
+
erubi (~> 1.4)
|
|
22
|
+
rails-dom-testing (~> 2.0)
|
|
23
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
24
|
+
activemodel (6.1.4)
|
|
25
|
+
activesupport (= 6.1.4)
|
|
26
|
+
activesupport (6.1.4)
|
|
27
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
28
|
+
i18n (>= 1.6, < 2)
|
|
29
|
+
minitest (>= 5.1)
|
|
30
|
+
tzinfo (~> 2.0)
|
|
31
|
+
zeitwerk (~> 2.3)
|
|
32
|
+
ast (2.4.2)
|
|
33
|
+
builder (3.2.4)
|
|
34
|
+
byebug (11.1.3)
|
|
35
|
+
concurrent-ruby (1.1.9)
|
|
36
|
+
crass (1.0.6)
|
|
37
|
+
diff-lcs (1.4.4)
|
|
38
|
+
erubi (1.10.0)
|
|
39
|
+
faker (2.18.0)
|
|
40
|
+
i18n (>= 1.6, < 2)
|
|
41
|
+
i18n (1.8.10)
|
|
42
|
+
concurrent-ruby (~> 1.0)
|
|
43
|
+
loofah (2.10.0)
|
|
44
|
+
crass (~> 1.0.2)
|
|
45
|
+
nokogiri (>= 1.5.9)
|
|
46
|
+
mini_portile2 (2.5.3)
|
|
47
|
+
minitest (5.14.4)
|
|
48
|
+
nokogiri (1.11.7)
|
|
49
|
+
mini_portile2 (~> 2.5.0)
|
|
50
|
+
racc (~> 1.4)
|
|
51
|
+
parallel (1.20.1)
|
|
52
|
+
parser (3.0.2.0)
|
|
53
|
+
ast (~> 2.4.1)
|
|
54
|
+
racc (1.5.2)
|
|
55
|
+
rack (2.2.3)
|
|
56
|
+
rack-test (1.1.0)
|
|
57
|
+
rack (>= 1.0, < 3)
|
|
58
|
+
rails-dom-testing (2.0.3)
|
|
59
|
+
activesupport (>= 4.2.0)
|
|
60
|
+
nokogiri (>= 1.6)
|
|
61
|
+
rails-html-sanitizer (1.3.0)
|
|
62
|
+
loofah (~> 2.3)
|
|
63
|
+
rainbow (3.0.0)
|
|
64
|
+
rake (12.3.3)
|
|
65
|
+
regexp_parser (2.1.1)
|
|
66
|
+
rexml (3.2.5)
|
|
67
|
+
rspec (3.10.0)
|
|
68
|
+
rspec-core (~> 3.10.0)
|
|
69
|
+
rspec-expectations (~> 3.10.0)
|
|
70
|
+
rspec-mocks (~> 3.10.0)
|
|
71
|
+
rspec-core (3.10.1)
|
|
72
|
+
rspec-support (~> 3.10.0)
|
|
73
|
+
rspec-expectations (3.10.1)
|
|
74
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
75
|
+
rspec-support (~> 3.10.0)
|
|
76
|
+
rspec-mocks (3.10.2)
|
|
77
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
78
|
+
rspec-support (~> 3.10.0)
|
|
79
|
+
rspec-support (3.10.2)
|
|
80
|
+
rubocop (1.18.3)
|
|
81
|
+
parallel (~> 1.10)
|
|
82
|
+
parser (>= 3.0.0.0)
|
|
83
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
84
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
85
|
+
rexml
|
|
86
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
|
87
|
+
ruby-progressbar (~> 1.7)
|
|
88
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
89
|
+
rubocop-ast (1.7.0)
|
|
90
|
+
parser (>= 3.0.1.1)
|
|
91
|
+
ruby-progressbar (1.11.0)
|
|
92
|
+
tzinfo (2.0.4)
|
|
93
|
+
concurrent-ruby (~> 1.0)
|
|
94
|
+
unicode-display_width (2.0.0)
|
|
95
|
+
zeitwerk (2.4.2)
|
|
96
|
+
|
|
97
|
+
PLATFORMS
|
|
98
|
+
ruby
|
|
99
|
+
|
|
100
|
+
DEPENDENCIES
|
|
101
|
+
byebug
|
|
102
|
+
faker
|
|
103
|
+
rake (~> 12.0)
|
|
104
|
+
rspec (~> 3.0)
|
|
105
|
+
rubocop
|
|
106
|
+
zantetsuken!
|
|
107
|
+
|
|
108
|
+
BUNDLED WITH
|
|
109
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Simon Fish
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Zantetsuken
|
|
2
|
+
|
|
3
|
+
The Content Security Policy (CSP) initializer in Rails can get cluttered
|
|
4
|
+
fast. Break it down with the help of this gem.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Add `gem 'zantetsuken'` to your Gemfile and run `bundle install`.
|
|
9
|
+
Alternatively, install the gem directly by calling `gem install
|
|
10
|
+
zantetsuken` in your shell.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
Update `config/initializer/content_security_policy` to include the
|
|
15
|
+
following:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
Rails.application.config.content_security_policy do |policy|
|
|
19
|
+
Zantetsuken.load(policy)
|
|
20
|
+
end
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This will compose any rulesets you've defined under the
|
|
24
|
+
`Zantetsuken::Ruleset` module into a single
|
|
25
|
+
`ActionDispatch::ContentSecurityPolicy`, which is what Rails uses under
|
|
26
|
+
the hood to build your CSP.
|
|
27
|
+
|
|
28
|
+
### Defining rulesets
|
|
29
|
+
|
|
30
|
+
You should define your rulesets under
|
|
31
|
+
`app/lib/zantetsuken/ruleset`. Here's an example:
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
# app/lib/zantetsuken/ruleset/stripe/js.rb
|
|
35
|
+
|
|
36
|
+
# frozen_string_literal: true
|
|
37
|
+
|
|
38
|
+
module Zantetsuken
|
|
39
|
+
module Ruleset
|
|
40
|
+
module Stripe
|
|
41
|
+
# Used for loading Stripe's JS library.
|
|
42
|
+
class Js < Base
|
|
43
|
+
ruleset do
|
|
44
|
+
self.connect_src = 'https://api.stripe.com'
|
|
45
|
+
self.frame_src = 'https://js.stripe.com', 'https://hooks.stripe.com'
|
|
46
|
+
self.script_src = 'https://js.stripe.com'
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
You should inherit from `Zantetsuken::Ruleset::Base` so that the ruleset can be
|
|
55
|
+
composed with others.
|
|
56
|
+
|
|
57
|
+
## Contributing
|
|
58
|
+
|
|
59
|
+
Contributions are welcome by way of a pull request. Pull requests with
|
|
60
|
+
failing test cases are preferable to issues, if you feel comfortable
|
|
61
|
+
doing that.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'zantetsuken'
|
|
6
|
+
|
|
7
|
+
# Mock environment checks
|
|
8
|
+
module Rails
|
|
9
|
+
mattr_accessor :env, default: 'development'.inquiry
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
13
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
14
|
+
|
|
15
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
16
|
+
# require "pry"
|
|
17
|
+
# Pry.start
|
|
18
|
+
|
|
19
|
+
require 'irb'
|
|
20
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/zantetsuken.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_model'
|
|
4
|
+
require 'action_dispatch'
|
|
5
|
+
require 'active_support/core_ext/object/instance_variables'
|
|
6
|
+
require 'active_support/core_ext/array/wrap'
|
|
7
|
+
require 'active_support/core_ext/string/inquiry'
|
|
8
|
+
|
|
9
|
+
require_relative 'zantetsuken/ruleset'
|
|
10
|
+
require_relative 'zantetsuken/ruleset/base'
|
|
11
|
+
|
|
12
|
+
# A policy that defines sources from which content should be able to load in the
|
|
13
|
+
# browser when you visit this Rails application.
|
|
14
|
+
module Zantetsuken
|
|
15
|
+
class << self
|
|
16
|
+
def load(base_policy = ActionDispatch::ContentSecurityPolicy.new)
|
|
17
|
+
self::Ruleset.load(base_policy)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Zantetsuken
|
|
4
|
+
# Contains definitions for sets of rules that should be applied as part of the
|
|
5
|
+
# content security policy.
|
|
6
|
+
module Ruleset
|
|
7
|
+
class << self
|
|
8
|
+
def load(base_policy = ActionDispatch::ContentSecurityPolicy.new)
|
|
9
|
+
load_all_rulesets_in(self).to_actiondispatch_csp(base_policy)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def load_all_rulesets_in(mod, base_policy = self::Base.new)
|
|
15
|
+
mod.constants(false).reduce(base_policy) do |policy, ruleset_class|
|
|
16
|
+
klass = mod.const_get(ruleset_class)
|
|
17
|
+
if klass <= Base
|
|
18
|
+
klass.new.load? ? policy.add(klass.new) : policy
|
|
19
|
+
else
|
|
20
|
+
load_all_rulesets_in(klass, policy)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Zantetsuken
|
|
4
|
+
# A set of rules that comprises a Content Security Policy.
|
|
5
|
+
module Ruleset
|
|
6
|
+
# Base class for rulesets. Defines the rules to be applied and the behavior
|
|
7
|
+
# for composing these rulesets into a single instance of
|
|
8
|
+
# ActionDispatch::ContentSecurityPolicy.
|
|
9
|
+
class Base
|
|
10
|
+
include ActiveModel::AttributeAssignment
|
|
11
|
+
extend ActiveModel::Callbacks
|
|
12
|
+
|
|
13
|
+
define_model_callbacks :initialize
|
|
14
|
+
|
|
15
|
+
attr_accessor :base_uri, :default_src, :font_src, :img_src, :object_src, :script_src, :frame_src, :connect_src,
|
|
16
|
+
:style_src, :child_src, :form_action, :media_src, :report_uri
|
|
17
|
+
|
|
18
|
+
class << self
|
|
19
|
+
def ruleset(&block)
|
|
20
|
+
after_initialize(&block)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def initialize(**attributes)
|
|
25
|
+
run_callbacks :initialize do
|
|
26
|
+
assign_attributes(attributes)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def add(ruleset)
|
|
31
|
+
tap do
|
|
32
|
+
assign_attributes(
|
|
33
|
+
to_h.merge(ruleset.to_h) do |_, existing_rules, new_rules|
|
|
34
|
+
Array.wrap(existing_rules) | Array.wrap(new_rules)
|
|
35
|
+
end
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_h
|
|
41
|
+
instance_values.symbolize_keys
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def to_actiondispatch_csp(policy)
|
|
45
|
+
instance_values.each do |rule_name, attribute|
|
|
46
|
+
policy.public_send(rule_name, *attribute)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def load?
|
|
51
|
+
true
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/zantetsuken.gemspec
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/zantetsuken/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'zantetsuken'
|
|
7
|
+
spec.version = Zantetsuken::VERSION
|
|
8
|
+
spec.authors = ['Simon Fish']
|
|
9
|
+
spec.email = ['si@mon.fish']
|
|
10
|
+
|
|
11
|
+
spec.summary = "Organize and build your app's Content Security Policy"
|
|
12
|
+
spec.description = 'The Content Security Policy (CSP) in Rails can get big fast. Slice it up with this gem.'
|
|
13
|
+
spec.homepage = 'https://github.com/raisedevs/zantetsuken'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/raisedevs/zantetsuken'
|
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/raisedevs/zantetsuken/blob/main/CHANGELOG.md'
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = 'exe'
|
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ['lib']
|
|
29
|
+
|
|
30
|
+
spec.add_runtime_dependency 'actionpack', '~> 6.1.4', '>= 6.0.0'
|
|
31
|
+
spec.add_runtime_dependency 'activemodel', '~> 6.1.4', '>= 6.0.0'
|
|
32
|
+
spec.add_development_dependency 'byebug'
|
|
33
|
+
spec.add_development_dependency 'faker'
|
|
34
|
+
spec.add_development_dependency 'rspec'
|
|
35
|
+
spec.add_development_dependency 'rubocop'
|
|
36
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: zantetsuken
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Simon Fish
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-07-12 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: actionpack
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 6.1.4
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 6.0.0
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - "~>"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 6.1.4
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 6.0.0
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: activemodel
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 6.1.4
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: 6.0.0
|
|
43
|
+
type: :runtime
|
|
44
|
+
prerelease: false
|
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - "~>"
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: 6.1.4
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: 6.0.0
|
|
53
|
+
- !ruby/object:Gem::Dependency
|
|
54
|
+
name: byebug
|
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '0'
|
|
60
|
+
type: :development
|
|
61
|
+
prerelease: false
|
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0'
|
|
67
|
+
- !ruby/object:Gem::Dependency
|
|
68
|
+
name: faker
|
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
type: :development
|
|
75
|
+
prerelease: false
|
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '0'
|
|
81
|
+
- !ruby/object:Gem::Dependency
|
|
82
|
+
name: rspec
|
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
type: :development
|
|
89
|
+
prerelease: false
|
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - ">="
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
95
|
+
- !ruby/object:Gem::Dependency
|
|
96
|
+
name: rubocop
|
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - ">="
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
type: :development
|
|
103
|
+
prerelease: false
|
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - ">="
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '0'
|
|
109
|
+
description: The Content Security Policy (CSP) in Rails can get big fast. Slice it
|
|
110
|
+
up with this gem.
|
|
111
|
+
email:
|
|
112
|
+
- si@mon.fish
|
|
113
|
+
executables: []
|
|
114
|
+
extensions: []
|
|
115
|
+
extra_rdoc_files: []
|
|
116
|
+
files:
|
|
117
|
+
- ".github/workflows/gem-push.yml"
|
|
118
|
+
- ".github/workflows/main.yml"
|
|
119
|
+
- ".gitignore"
|
|
120
|
+
- ".rubocop.yml"
|
|
121
|
+
- ".rubocop_todo.yml"
|
|
122
|
+
- CODE_OF_CONDUCT.md
|
|
123
|
+
- Gemfile
|
|
124
|
+
- Gemfile.lock
|
|
125
|
+
- LICENSE.txt
|
|
126
|
+
- README.md
|
|
127
|
+
- Rakefile
|
|
128
|
+
- bin/console
|
|
129
|
+
- bin/setup
|
|
130
|
+
- lib/zantetsuken.rb
|
|
131
|
+
- lib/zantetsuken/ruleset.rb
|
|
132
|
+
- lib/zantetsuken/ruleset/base.rb
|
|
133
|
+
- lib/zantetsuken/version.rb
|
|
134
|
+
- zantetsuken.gemspec
|
|
135
|
+
homepage: https://github.com/raisedevs/zantetsuken
|
|
136
|
+
licenses:
|
|
137
|
+
- MIT
|
|
138
|
+
metadata:
|
|
139
|
+
homepage_uri: https://github.com/raisedevs/zantetsuken
|
|
140
|
+
source_code_uri: https://github.com/raisedevs/zantetsuken
|
|
141
|
+
changelog_uri: https://github.com/raisedevs/zantetsuken/blob/main/CHANGELOG.md
|
|
142
|
+
post_install_message:
|
|
143
|
+
rdoc_options: []
|
|
144
|
+
require_paths:
|
|
145
|
+
- lib
|
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
|
+
requirements:
|
|
148
|
+
- - ">="
|
|
149
|
+
- !ruby/object:Gem::Version
|
|
150
|
+
version: 2.5.0
|
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
|
+
requirements:
|
|
153
|
+
- - ">="
|
|
154
|
+
- !ruby/object:Gem::Version
|
|
155
|
+
version: '0'
|
|
156
|
+
requirements: []
|
|
157
|
+
rubygems_version: 3.1.4
|
|
158
|
+
signing_key:
|
|
159
|
+
specification_version: 4
|
|
160
|
+
summary: Organize and build your app's Content Security Policy
|
|
161
|
+
test_files: []
|