jekyll-content-security-policy-generator 1.6.2 → 1.6.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc3017347d7d66db1c62f2b30d65b65ecdda0977d08c608d4d32ae8e44029160
4
- data.tar.gz: d0ae7507c626512b6b7dfaf965416eda4f1bec47528f12b424700eda462919b4
3
+ metadata.gz: 2033feca49aeb4a10933f1c7fd8f628b3053030c3e89017f4eff63e716a74afc
4
+ data.tar.gz: c0ec4dd232b0fa6daad0e73ca20bbd7b69b6ff6738620329b55a66f6ba748faf
5
5
  SHA512:
6
- metadata.gz: c4bdaa964ad16cf409231e5c1f7a4cf70aba062a65329ccb2763883963c505330167409f918cbbc2fe1c2b7c3c8da7f9a028afd6cdd80bba247763ce28946166
7
- data.tar.gz: efa5b000702d5fee29b8419a802fa681b68ada12bca097f5f57e1339227a5707477782aeb245e3ed7817b83ef1d43338f436535b07603cec23d5326274d9ad71
6
+ metadata.gz: 65f682c0f7d2b5c8e59918e3a93afb4c2f53ea3c933a860a52aec44325a931cf236d09ff900f3c4d2ad97889d10bc13a6d568710ba363364191de3a5e4b3a699
7
+ data.tar.gz: fbdbd9a95672881e602c0445a1030754cfdca0eefc7c931ecb09903250da3cadf6a95e6f9d87c83ac7091392f9ed9978b821a8b5ea561bf60f0811a97f12cb46
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ .
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
data/Cover.png ADDED
Binary file
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # jekyll-content-security-policy-generator Plugin
2
2
 
3
+ ![Jekyll Image Cover](Cover.png)
4
+
3
5
  This Jekyll plugin automatically builds an HTML content-security-policy for a Jekyll site. The plugin
4
6
  will scan ```.html``` files generated by Jekyll and attempt to locate images, styles, scripts, frames etc and build a
5
7
  content security policy HTML meta tag. The script will also generate SHA256 hashes for inline scripts and styles. If
@@ -18,18 +20,51 @@ To speed up development of Jekyll based sites whilst also helping to generate se
18
20
  * Creates or reuses an HTTP meta tag for the content security policy.
19
21
  * Finds all images, styles, scripts and frames with external URLs and builds CSP.
20
22
  * Converts style attributes into ```<style>``` elements.
23
+ * If a page already has a content-security-policy tag, (such as your index.html file), the script will reuse it.
24
+ * Image URLs such as https://strongscot.com/images/logo.svg will have a rule such as https://strongscot.com/images/
25
+
26
+ ## Upcoming Features
27
+
28
+ * Ability to specify how lax the domain rules can be. For example, ```https://strongscot.com/images/logo.svg``` would be converted to
29
+ ```https://strongscot.com/images/``` under strict and ```https://strongscot.com``` under relaxed.
30
+ * Ability in site.yaml file to specify what files it should parse, at the moment its only ```.html```.
21
31
 
22
32
  ## Installation
23
33
 
24
- Install the gem:
34
+ Add the plugin your Gemfile within the jekyll_plugins group:
35
+
36
+ ```
37
+ group :jekyll_plugins do
38
+ gem 'jekyll-content-security-policy-generator'
39
+ ... other gem files
40
+ end
41
+ ```
42
+
43
+ Then install
44
+
45
+ ```
46
+ bundle install
47
+ ```
48
+
49
+ ## Nokogiri Error on Mac?
50
+
51
+ For some reason, Nokogiri will install with both the ARM (M1) and x86 variants which will confuse bundler. Best way I found to fix this was to open the Gemfile.lock and remove the:
52
+
53
+ ```
54
+ nokogiri (1.11.3-arm64-darwin)
55
+ racc (~> 1.4)
56
+ ```
25
57
 
26
- ```gem install jekyll-content-security-policy-generator```
58
+ Or the x86 if you have an M1 mac.
27
59
 
28
- Then add this to your _config.yml:
60
+ Alternatively, you can add ```nokogiri``` to your Gemfile, like so:
29
61
 
30
62
  ```
31
- plugins:
32
- - jekyll-content-security-policy-generator
63
+ group :jekyll_plugins do
64
+ gem 'nokogiri'
65
+ gem 'jekyll-content-security-policy-generator'
66
+ ... other gem files
67
+ end
33
68
  ```
34
69
 
35
70
  ## Support
@@ -1,10 +1,15 @@
1
1
  lib = File.expand_path("../lib", __FILE__)
2
+
2
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
  require "jekyll-content-security-policy-generator/version"
5
+
4
6
  Gem::Specification.new do |spec|
5
7
  spec.name = "jekyll-content-security-policy-generator"
6
8
  spec.summary = "Helps generate a content security policy."
7
- spec.description = "Helps generate a content security policy. Locates inline scripts, images, frames etc."
9
+ spec.description = "Will generate a content-security-policy based on images, scripts, stylesheets, frames and"\
10
+ "others on each generated page. This script assumes that all your linked resources as 'safe'."\
11
+ "Style attributes will also be converted into <style> elements and SHA256 hashes will be"\
12
+ "generated for inline styles/scripts."
8
13
  spec.version = JekyllContentSecurityPolicyGenerator::VERSION
9
14
  spec.authors = ["strongscot"]
10
15
  spec.email = ["mail@strongscot.com"]
@@ -12,12 +17,10 @@ Gem::Specification.new do |spec|
12
17
  spec.licenses = ["MIT"]
13
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
14
19
  spec.require_paths = ["lib"]
15
- spec.add_dependency "jekyll"
16
- spec.add_dependency "nokogiri"
17
- spec.add_dependency "digest"
18
- spec.add_development_dependency "rake"
19
- spec.add_development_dependency "rspec"
20
- spec.add_development_dependency "rubocop"
21
- spec.add_development_dependency "nokogiri"
22
- spec.add_development_dependency "digest"
20
+ spec.add_dependency 'jekyll'
21
+ spec.add_dependency 'digest'
22
+ spec.add_dependency 'nokogiri'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'rubocop'
23
26
  end
@@ -2,6 +2,7 @@ require 'jekyll'
2
2
  require 'nokogiri'
3
3
  require 'digest'
4
4
  require 'open-uri'
5
+ require 'uri'
5
6
 
6
7
  ##
7
8
  # Provides the ability to generate a content security policy for inline scripts and styles.
@@ -30,11 +31,19 @@ module Jekyll
30
31
  def generate_convert_security_policy_meta_tag
31
32
  meta_content = ""
32
33
 
34
+ @csp_script_src = @csp_script_src.uniq
35
+ @csp_image_src = @csp_image_src.uniq
36
+ @csp_style_src = @csp_style_src.uniq
37
+ @csp_script_src = @csp_script_src.uniq
38
+ @csp_unknown = @csp_unknown.uniq
39
+
33
40
  if @csp_frame_src.length > 0
41
+ @csp_script_src.uniq
34
42
  meta_content += "frame-src " + @csp_frame_src.join(' ') + '; '
35
43
  end
36
44
 
37
45
  if @csp_image_src.length > 0
46
+ Jekyll.logger.warn @csp_image_src
38
47
  meta_content += "img-src " + @csp_image_src.join(' ') + '; '
39
48
  end
40
49
 
@@ -55,10 +64,10 @@ module Jekyll
55
64
  end
56
65
 
57
66
  if @nokogiri.at("head")
58
- Jekyll.logger.info "Generated content security policy, inserted in HEAD."
67
+ #Jekyll.logger.info "Generated content security policy, inserted in HEAD."
59
68
  @nokogiri.at("head") << "<meta http-equiv=\"Content-Security-Policy\" content=\"" + meta_content + "\">"
60
69
  elsif @nokogiri.at("body")
61
- Jekyll.logger.info "Generated content security policy, inserted in BODY."
70
+ #Jekyll.logger.info "Generated content security policy, inserted in BODY."
62
71
  @nokogiri.at("body") << "<meta http-equiv=\"Content-Security-Policy\" content=\"" + meta_content + "\">"
63
72
  else
64
73
  Jekyll.logger.error "Generated content security policy but found no-where to insert it."
@@ -84,16 +93,12 @@ module Jekyll
84
93
 
85
94
  if policy_parts[0] == 'script-src'
86
95
  @csp_script_src.concat(policy_parts.drop(1))
87
- @csp_script_src = @csp_script_src.uniq
88
96
  elsif policy_parts[0] == 'style-src'
89
97
  @csp_style_src.concat(policy_parts.drop(1))
90
- @csp_style_src = @csp_style_src.uniq
91
- elsif policy_parts[0] == 'image-src'
98
+ elsif policy_parts[0] == 'img-src'
92
99
  @csp_image_src.concat(policy_parts.drop(1))
93
- @csp_image_src = @csp_image_src.uniq
94
100
  elsif policy_parts[0] == 'frame-src'
95
101
  @csp_frame_src.concat(policy_parts.drop(1))
96
- @csp_frame_src = @csp_frame_src.uniq
97
102
  else
98
103
  @csp_unknown.concat([policy_parts])
99
104
  end
@@ -102,6 +107,10 @@ module Jekyll
102
107
  Jekyll.logger.warn "Incorrect existing content security policy meta tag found, skipping."
103
108
  end
104
109
  end
110
+
111
+ @nokogiri.search('meta[http-equiv="Content-Security-Policy"]').each do |el|
112
+ el.remove
113
+ end
105
114
  end
106
115
  end
107
116
 
@@ -115,7 +124,8 @@ module Jekyll
115
124
  if find.attr('id')
116
125
  element_id = find.attr('id')
117
126
  else
118
- element_id = Digest::MD5.hexdigest find_src + "#{Random.rand(11)}"
127
+ hash = Digest::MD5.hexdigest find_src + "#{Random.rand(11)}"
128
+ element_id = "csp-gen-" + hash
119
129
  find["id"] = element_id
120
130
  end
121
131
 
@@ -124,11 +134,11 @@ module Jekyll
124
134
 
125
135
  if @nokogiri.at('head')
126
136
  @nokogiri.at('head') << new_element
127
- Jekyll.logger.info'Converting style attribute to inline style, inserted into HEAD.'
137
+ #Jekyll.logger.info'Converting style attribute to inline style, inserted into HEAD.'
128
138
  else
129
139
  if @nokogiri.at('body')
130
140
  @nokogiri.at('body') << new_element
131
- Jekyll.logger.info'Converting style attribute to inline style, inserted into BODY.'
141
+ #Jekyll.logger.info'Converting style attribute to inline style, inserted into BODY.'
132
142
  else
133
143
  Jekyll.logger.warn'Unable to convert style attribute to inline style, no HEAD or BODY found.'
134
144
  end
@@ -143,10 +153,23 @@ module Jekyll
143
153
  @nokogiri.css('img').each do |find|
144
154
  find_src = find.attr('src')
145
155
 
146
- if find_src.start_with?('http', 'https')
156
+ if find_src and find_src.start_with?('http', 'https')
147
157
  @csp_image_src.push find_src.match(/(.*\/)+(.*$)/)[1]
148
158
  end
149
159
  end
160
+
161
+ @nokogiri.css('style').each do |find|
162
+ finds = find.content.scan(/url\(([^\)]+)\)/)
163
+
164
+ finds.each do |innerFind|
165
+ innerFind = innerFind[0]
166
+ innerFind = innerFind.tr('\'"', '')
167
+ if innerFind.start_with?('http', 'https')
168
+ @csp_image_src.push self.get_domain(innerFind)
169
+ end
170
+ end
171
+ end
172
+
150
173
  end
151
174
 
152
175
  ##
@@ -156,7 +179,7 @@ module Jekyll
156
179
  if find.attr('src')
157
180
  find_src = find.attr('src')
158
181
 
159
- if find_src.start_with?('http', 'https')
182
+ if find_src and find_src.start_with?('http', 'https')
160
183
  @csp_script_src.push find_src.match(/(.*\/)+(.*$)/)[1]
161
184
  end
162
185
 
@@ -173,7 +196,7 @@ module Jekyll
173
196
  if find.attr('src')
174
197
  find_src = find.attr('src')
175
198
 
176
- if find_src.start_with?('http', 'https')
199
+ if find_src and find_src.start_with?('http', 'https')
177
200
  @csp_style_src.push find_src.match(/(.*\/)+(.*$)/)[1]
178
201
  end
179
202
 
@@ -189,12 +212,17 @@ module Jekyll
189
212
  @nokogiri.css('iframe').each do |find|
190
213
  find_src = find.attr('src')
191
214
 
192
- if find_src.start_with?('http', 'https')
215
+ if find_src and find_src.start_with?('http', 'https')
193
216
  @csp_frame_src.push find_src.match(/(.*\/)+(.*$)/)[1]
194
217
  end
195
218
  end
196
219
  end
197
220
 
221
+ def get_domain(url)
222
+ uri = URI.parse(url)
223
+ "#{uri.scheme}://#{uri.host}"
224
+ end
225
+
198
226
  ##
199
227
  # Generate a content hash
200
228
  def generate_sha256_content_hash(content)
@@ -237,9 +265,8 @@ module Jekyll
237
265
  if File.extname(dest_path) == ".html"
238
266
  content_security_policy_generator = ContentSecurityPolicyGenerator.new output
239
267
  output = content_security_policy_generator.run
268
+ write_file_contents(dest_path, output)
240
269
  end
241
-
242
- write_file_contents(dest_path, output)
243
270
  end
244
271
 
245
272
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllContentSecurityPolicyGenerator
2
- VERSION = "1.6.2".freeze
2
+ VERSION = "1.6.11".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-content-security-policy-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - strongscot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-11 00:00:00.000000000 Z
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: nokogiri
28
+ name: digest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: digest
42
+ name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -94,36 +94,10 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: nokogiri
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: digest
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- description: Helps generate a content security policy. Locates inline scripts, images,
126
- frames etc.
97
+ description: Will generate a content-security-policy based on images, scripts, stylesheets,
98
+ frames andothers on each generated page. This script assumes that all your linked
99
+ resources as 'safe'.Style attributes will also be converted into <style> elements
100
+ and SHA256 hashes will begenerated for inline styles/scripts.
127
101
  email:
128
102
  - mail@strongscot.com
129
103
  executables: []
@@ -131,6 +105,8 @@ extensions: []
131
105
  extra_rdoc_files: []
132
106
  files:
133
107
  - ".gitignore"
108
+ - CODE_OF_CONDUCT.md
109
+ - Cover.png
134
110
  - LICENSE
135
111
  - Makefile
136
112
  - README.md