securitytxt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a94da8bb441d834511c0ee0a7109ec57b84e8319
4
+ data.tar.gz: 0db1beee347f72b1b8f82ba6f8f7b971c2f4e6be
5
+ SHA512:
6
+ metadata.gz: de2bdfdded9bbb839b7cd8046c0b4e00e327dbf57d3ce816c5bd5b7b603491c1f3c215ca688a2f1f09b6ba0ba75d085c8a1961ff9a8e4717faf4ab233f6d1873
7
+ data.tar.gz: 1bb67af19bad0e1e09a057e44dec68e2861ae1c3fcdb3820abe85177edef2b36957547f75b62384c1018d8e594e018683e994c99b222ddd2fec7591875aa3615
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Benoit Larroque
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # Security.txt toolbox for your Ruby app
2
+
3
+ This gem provides a Rack middleware and matching Rails engine
4
+ that will provides a nicely formatted [security.txt](https://tools.ietf.org/html/draft-foudil-securitytxt-02) for your application.
5
+ It also includes a generator and parser of security.txt files.
6
+
7
+ References:
8
+ * [security.txt rfc draft](https://tools.ietf.org/html/draft-foudil-securitytxt-02)
9
+ * [security.txt project on github](https://github.com/securitytxt/security-txt)
10
+ * [securitytxt.org](https://securitytxt.org/)
11
+
12
+
13
+ ## Installation
14
+ Add this line to your application's Gemfile:
15
+ ```ruby
16
+ gem 'securitytxt'
17
+ ```
18
+
19
+ And then execute:
20
+ ```bash
21
+ $ bundle
22
+ ```
23
+
24
+ ## Using the Rails engine
25
+ Create an initializer with the policy you want to set:
26
+ ```ruby
27
+ # config/initializers/securitytxt.rb
28
+ SecurityTxt.contact = "me@organization.com"
29
+ SecurityTxt.encryption = "https://www.mykey.com/pgp-key.txt"
30
+ ```
31
+
32
+ ## Using the Rack middleware
33
+ Add the middleware to your chain in your config.ru
34
+
35
+ ```ruby
36
+ require 'securitytxt'
37
+
38
+ policy = {
39
+ "contact" => "me@organization.com",
40
+ "encryption" => "https://www.mykey.com/pgp-key.txt"
41
+ }
42
+ use SecurityTxt::Middleware, policy
43
+ ```
44
+
45
+ ## Parsing a Security.txt
46
+
47
+ Simply passing a string should be enough to get data back
48
+
49
+ ```ruby
50
+ require "securitytxt/parser"
51
+ require "open-uri"
52
+ SecurityTxt::Parser.new.parse(open("https://securitytxt.org/.well-known/security.txt").read)
53
+ # Outputs {"contact"=>"https://hackerone.com/ed", "encryption"=>"https://keybase.pub/edoverflow/pgp_key.asc", "acknowledgements"=>"https://hackerone.com/ed/thanks"}
54
+ ```
55
+
56
+ ## Generating a Security.txt
57
+
58
+ ```ruby
59
+ require 'securitytxt/generator'
60
+ puts SecurityTxt::Generator.new({"contact"=>"https://hackerone.com/ed", "encryption"=>"https://keybase.pub/edoverflow/pgp_key.asc", "acknowledgements"=>"https://hackerone.com/ed/thanks"}).generate
61
+ # Outputs
62
+ #
63
+ # Contact: https://hackerone.com/ed
64
+ # Encryption: https://keybase.pub/edoverflow/pgp_key.asc
65
+ # Acknowledgements: https://hackerone.com/ed/thanks
66
+ ```
67
+
68
+ ## License
69
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SecurityTxt'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,36 @@
1
+ module SecurityTxt
2
+ # Generator of Security.txt
3
+ class Generator
4
+ attr_accessor :sections
5
+ def initialize(data = {})
6
+ @sections = data
7
+ end
8
+
9
+ def generate
10
+ ret = StringIO.new
11
+ sections.each do |name, value|
12
+ next if value.nil? || value.empty?
13
+ if value.is_a?(Array)
14
+ value.each { |subvalue| ret << "#{capitalize(name)}: #{subvalue}\n" }
15
+ else
16
+ ret << "#{capitalize(name)}: #{value}\n"
17
+ end
18
+ end
19
+ ret.string
20
+ end
21
+
22
+ protected
23
+
24
+ if ''.respond_to?(:capitalize)
25
+ def capitalize(w)
26
+ w.capitalize
27
+ end
28
+ else
29
+ # Stolen from rails
30
+ def capitalize(w)
31
+ (w.slice(0) || w.chars('')).upcase +
32
+ (w.slice(1..-1) || w.chars('')).downcase
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ module SecurityTxt
2
+ # Rack Middleware that generates a respond.txt
3
+ class Middleware
4
+ def initialize(app, sections = {})
5
+ @app = app
6
+ @sections = sections
7
+ end
8
+
9
+ def call(env)
10
+ req = Rack::Request.new(env)
11
+
12
+ sections = @sections
13
+ sections = @sections.call if @sections.respond_to?(:call)
14
+ if req.path == '/.well-known/security.txt' && !sections.empty?
15
+ return Rack::Response.new(Generator.new(sections).generate, 200,
16
+ 'Content-Type' => 'text/plain')
17
+ end
18
+ @app.call(env)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module SecurityTxt
2
+ # Parser of Security.txt
3
+ class Parser
4
+ def parse(str)
5
+ sections = {}
6
+ str.each_line do |line|
7
+ line.chomp!
8
+ l = line.to_s.gsub(/#.*$/, '')
9
+ next if l.index(': ').nil?
10
+ section, value = l.split(': ', 2)
11
+ key = section.to_s.downcase
12
+ current = sections[key]
13
+ case current
14
+ when NilClass
15
+ sections[key] = value
16
+ when Array
17
+ sections[key] << value.strip
18
+ else
19
+ sections[key] = [current, value]
20
+ end
21
+ end
22
+ sections
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module SecurityTxt
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'securitytxt/generator'
2
+ require 'securitytxt/middleware'
3
+
4
+ # Rails SecurityTXT generator
5
+ module SecurityTxt
6
+ SECTIONS = %i[acknowledgment contact encryption signature policy].freeze
7
+ SECTIONS.each do |section|
8
+ if defined?(Rails)
9
+ mattr_accessor section
10
+ else
11
+ attr_accessor section
12
+ end
13
+ end
14
+
15
+ if defined?(Rails)
16
+ # Rails engine that plugs middleware in application
17
+ class Application < Rails::Application
18
+ config = proc do
19
+ SecurityTxt::SECTIONS.inject({}) do |acc, v|
20
+ acc[v] = SecurityTxt.send(v)
21
+ acc
22
+ end
23
+ end
24
+ Rails.application.config.middleware.use SecurityTxt::Middleware, config
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_security_txt do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: securitytxt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Benoit Larroque
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.4
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: 'This gems includes various tools about security.txt for Ruby: A rails
42
+ engine, A Rack MiddleWare, a simple parser and generator '
43
+ email:
44
+ - benoit@sqreen.io
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - lib/securitytxt.rb
53
+ - lib/securitytxt/generator.rb
54
+ - lib/securitytxt/middleware.rb
55
+ - lib/securitytxt/parser.rb
56
+ - lib/securitytxt/version.rb
57
+ - lib/tasks/rails_security_txt_tasks.rake
58
+ homepage:
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.6.13
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Provides a tools about security.txt for Ruby
82
+ test_files: []