secure_headers 2.5.3 → 3.0.0.pre
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/.rspec +1 -0
- data/.travis.yml +2 -1
- data/Gemfile +9 -16
- data/README.md +154 -331
- data/Rakefile +2 -36
- data/lib/secure_headers/configuration.rb +189 -0
- data/lib/secure_headers/headers/content_security_policy.rb +341 -254
- data/lib/secure_headers/headers/public_key_pins.rb +43 -58
- data/lib/secure_headers/headers/strict_transport_security.rb +21 -49
- data/lib/secure_headers/headers/x_content_type_options.rb +18 -33
- data/lib/secure_headers/headers/x_download_options.rb +18 -33
- data/lib/secure_headers/headers/x_frame_options.rb +24 -34
- data/lib/secure_headers/headers/x_permitted_cross_domain_policies.rb +19 -34
- data/lib/secure_headers/headers/x_xss_protection.rb +17 -48
- data/lib/secure_headers/middleware.rb +15 -0
- data/lib/secure_headers/padrino.rb +1 -2
- data/lib/secure_headers/railtie.rb +9 -6
- data/lib/secure_headers/view_helper.rb +27 -43
- data/lib/secure_headers.rb +254 -61
- data/secure_headers.gemspec +7 -12
- data/spec/lib/secure_headers/configuration_spec.rb +80 -0
- data/spec/lib/secure_headers/headers/content_security_policy_spec.rb +111 -276
- data/spec/lib/secure_headers/headers/public_key_pins_spec.rb +17 -17
- data/spec/lib/secure_headers/headers/strict_transport_security_spec.rb +11 -43
- data/spec/lib/secure_headers/headers/x_content_type_options_spec.rb +11 -18
- data/spec/lib/secure_headers/headers/x_download_options_spec.rb +13 -17
- data/spec/lib/secure_headers/headers/x_frame_options_spec.rb +15 -17
- data/spec/lib/secure_headers/headers/x_permitted_cross_domain_policies_spec.rb +22 -39
- data/spec/lib/secure_headers/headers/x_xss_protection_spec.rb +20 -30
- data/spec/lib/secure_headers/middleware_spec.rb +40 -0
- data/spec/lib/secure_headers_spec.rb +201 -339
- data/spec/spec_helper.rb +30 -30
- data/upgrading-to-3-0.md +35 -0
- metadata +14 -100
- data/fixtures/rails_3_2_22/.rspec +0 -1
- data/fixtures/rails_3_2_22/Gemfile +0 -6
- data/fixtures/rails_3_2_22/README.rdoc +0 -261
- data/fixtures/rails_3_2_22/Rakefile +0 -7
- data/fixtures/rails_3_2_22/app/controllers/application_controller.rb +0 -4
- data/fixtures/rails_3_2_22/app/controllers/other_things_controller.rb +0 -5
- data/fixtures/rails_3_2_22/app/controllers/things_controller.rb +0 -5
- data/fixtures/rails_3_2_22/app/models/.gitkeep +0 -0
- data/fixtures/rails_3_2_22/app/views/layouts/application.html.erb +0 -11
- data/fixtures/rails_3_2_22/app/views/other_things/index.html.erb +0 -2
- data/fixtures/rails_3_2_22/app/views/things/index.html.erb +0 -1
- data/fixtures/rails_3_2_22/config/application.rb +0 -14
- data/fixtures/rails_3_2_22/config/boot.rb +0 -6
- data/fixtures/rails_3_2_22/config/environment.rb +0 -5
- data/fixtures/rails_3_2_22/config/environments/test.rb +0 -37
- data/fixtures/rails_3_2_22/config/initializers/secure_headers.rb +0 -16
- data/fixtures/rails_3_2_22/config/routes.rb +0 -4
- data/fixtures/rails_3_2_22/config/script_hashes.yml +0 -5
- data/fixtures/rails_3_2_22/config.ru +0 -7
- data/fixtures/rails_3_2_22/lib/assets/.gitkeep +0 -0
- data/fixtures/rails_3_2_22/lib/tasks/.gitkeep +0 -0
- data/fixtures/rails_3_2_22/log/.gitkeep +0 -0
- data/fixtures/rails_3_2_22/spec/controllers/other_things_controller_spec.rb +0 -83
- data/fixtures/rails_3_2_22/spec/controllers/things_controller_spec.rb +0 -54
- data/fixtures/rails_3_2_22/spec/spec_helper.rb +0 -15
- data/fixtures/rails_3_2_22/vendor/assets/javascripts/.gitkeep +0 -0
- data/fixtures/rails_3_2_22/vendor/assets/stylesheets/.gitkeep +0 -0
- data/fixtures/rails_3_2_22/vendor/plugins/.gitkeep +0 -0
- data/fixtures/rails_3_2_22_no_init/.rspec +0 -1
- data/fixtures/rails_3_2_22_no_init/Gemfile +0 -6
- data/fixtures/rails_3_2_22_no_init/README.rdoc +0 -261
- data/fixtures/rails_3_2_22_no_init/Rakefile +0 -7
- data/fixtures/rails_3_2_22_no_init/app/controllers/application_controller.rb +0 -4
- data/fixtures/rails_3_2_22_no_init/app/controllers/other_things_controller.rb +0 -20
- data/fixtures/rails_3_2_22_no_init/app/controllers/things_controller.rb +0 -5
- data/fixtures/rails_3_2_22_no_init/app/models/.gitkeep +0 -0
- data/fixtures/rails_3_2_22_no_init/app/views/layouts/application.html.erb +0 -12
- data/fixtures/rails_3_2_22_no_init/app/views/other_things/index.html.erb +0 -1
- data/fixtures/rails_3_2_22_no_init/app/views/things/index.html.erb +0 -0
- data/fixtures/rails_3_2_22_no_init/config/application.rb +0 -17
- data/fixtures/rails_3_2_22_no_init/config/boot.rb +0 -6
- data/fixtures/rails_3_2_22_no_init/config/environment.rb +0 -5
- data/fixtures/rails_3_2_22_no_init/config/environments/test.rb +0 -37
- data/fixtures/rails_3_2_22_no_init/config/routes.rb +0 -4
- data/fixtures/rails_3_2_22_no_init/config.ru +0 -4
- data/fixtures/rails_3_2_22_no_init/lib/assets/.gitkeep +0 -0
- data/fixtures/rails_3_2_22_no_init/lib/tasks/.gitkeep +0 -0
- data/fixtures/rails_3_2_22_no_init/log/.gitkeep +0 -0
- data/fixtures/rails_3_2_22_no_init/spec/controllers/other_things_controller_spec.rb +0 -56
- data/fixtures/rails_3_2_22_no_init/spec/controllers/things_controller_spec.rb +0 -54
- data/fixtures/rails_3_2_22_no_init/spec/spec_helper.rb +0 -5
- data/fixtures/rails_3_2_22_no_init/vendor/assets/javascripts/.gitkeep +0 -0
- data/fixtures/rails_3_2_22_no_init/vendor/assets/stylesheets/.gitkeep +0 -0
- data/fixtures/rails_3_2_22_no_init/vendor/plugins/.gitkeep +0 -0
- data/fixtures/rails_4_1_8/Gemfile +0 -5
- data/fixtures/rails_4_1_8/README.rdoc +0 -28
- data/fixtures/rails_4_1_8/Rakefile +0 -6
- data/fixtures/rails_4_1_8/app/controllers/application_controller.rb +0 -4
- data/fixtures/rails_4_1_8/app/controllers/concerns/.keep +0 -0
- data/fixtures/rails_4_1_8/app/controllers/other_things_controller.rb +0 -5
- data/fixtures/rails_4_1_8/app/controllers/things_controller.rb +0 -5
- data/fixtures/rails_4_1_8/app/models/.keep +0 -0
- data/fixtures/rails_4_1_8/app/models/concerns/.keep +0 -0
- data/fixtures/rails_4_1_8/app/views/layouts/application.html.erb +0 -11
- data/fixtures/rails_4_1_8/app/views/other_things/index.html.erb +0 -2
- data/fixtures/rails_4_1_8/app/views/things/index.html.erb +0 -1
- data/fixtures/rails_4_1_8/config/application.rb +0 -15
- data/fixtures/rails_4_1_8/config/boot.rb +0 -4
- data/fixtures/rails_4_1_8/config/environment.rb +0 -5
- data/fixtures/rails_4_1_8/config/environments/test.rb +0 -10
- data/fixtures/rails_4_1_8/config/initializers/secure_headers.rb +0 -16
- data/fixtures/rails_4_1_8/config/routes.rb +0 -4
- data/fixtures/rails_4_1_8/config/script_hashes.yml +0 -5
- data/fixtures/rails_4_1_8/config/secrets.yml +0 -22
- data/fixtures/rails_4_1_8/config.ru +0 -4
- data/fixtures/rails_4_1_8/lib/assets/.keep +0 -0
- data/fixtures/rails_4_1_8/lib/tasks/.keep +0 -0
- data/fixtures/rails_4_1_8/log/.keep +0 -0
- data/fixtures/rails_4_1_8/spec/controllers/other_things_controller_spec.rb +0 -83
- data/fixtures/rails_4_1_8/spec/controllers/things_controller_spec.rb +0 -59
- data/fixtures/rails_4_1_8/spec/spec_helper.rb +0 -15
- data/fixtures/rails_4_1_8/vendor/assets/javascripts/.keep +0 -0
- data/fixtures/rails_4_1_8/vendor/assets/stylesheets/.keep +0 -0
- data/lib/secure_headers/controller_extension.rb +0 -158
- data/lib/secure_headers/hash_helper.rb +0 -7
- data/lib/secure_headers/header.rb +0 -5
- data/lib/secure_headers/headers/content_security_policy/script_hash_middleware.rb +0 -22
- data/lib/secure_headers/version.rb +0 -3
- data/lib/tasks/tasks.rake +0 -48
- data/spec/lib/secure_headers/headers/content_security_policy/script_hash_middleware_spec.rb +0 -46
|
File without changes
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
require 'secure_headers/headers/content_security_policy/script_hash_middleware'
|
|
4
|
-
|
|
5
|
-
describe OtherThingsController, :type => :controller do
|
|
6
|
-
include Rack::Test::Methods
|
|
7
|
-
|
|
8
|
-
def app
|
|
9
|
-
OtherThingsController.action(:index)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def request(opts = {})
|
|
13
|
-
options = opts.merge(
|
|
14
|
-
{
|
|
15
|
-
'HTTPS' => 'on',
|
|
16
|
-
'HTTP_USER_AGENT' => "Mozilla/5.0 (Macintosh; Intel Mac OS X 1084) AppleWebKit/537.22 (KHTML like Gecko) Chrome/25.0.1364.99 Safari/537.22"
|
|
17
|
-
}
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Rack::MockRequest.env_for('/', options)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
describe "headers" do
|
|
26
|
-
before(:each) do
|
|
27
|
-
_, @env = app.call(request)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "sets the X-XSS-Protection header" do
|
|
31
|
-
get '/'
|
|
32
|
-
expect(@env['X-XSS-Protection']).to eq('1; mode=block')
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "sets the X-Frame-Options header" do
|
|
36
|
-
get '/'
|
|
37
|
-
expect(@env['X-Frame-Options']).to eq('SAMEORIGIN')
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "sets the CSP header with a local reference to a nonce" do
|
|
41
|
-
middleware = ::SecureHeaders::ContentSecurityPolicy::ScriptHashMiddleware.new(app)
|
|
42
|
-
_, env = middleware.call(request(@env))
|
|
43
|
-
expect(env['Content-Security-Policy-Report-Only']).to match(/script-src[^;]*'nonce-[a-zA-Z0-9\+\/=]{44}'/)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "sets the required hashes to whitelist inline script" do
|
|
47
|
-
middleware = ::SecureHeaders::ContentSecurityPolicy::ScriptHashMiddleware.new(app)
|
|
48
|
-
_, env = middleware.call(request(@env))
|
|
49
|
-
hashes = ['sha256-VjDxT7saxd2FgaUQQTWw/jsTnvonaoCP/ACWDBTpyhU=', 'sha256-ZXAcP8a0y1pPMTJW8pUr43c+XBkgYQBwHOPvXk9mq5A=']
|
|
50
|
-
hashes.each do |hash|
|
|
51
|
-
expect(env['Content-Security-Policy-Report-Only']).to include(hash)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "sets the Strict-Transport-Security header" do
|
|
56
|
-
get '/'
|
|
57
|
-
expect(@env['Strict-Transport-Security']).to eq("max-age=315576000")
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "sets the X-Download-Options header" do
|
|
61
|
-
get '/'
|
|
62
|
-
expect(@env['X-Download-Options']).to eq('noopen')
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "sets the X-Content-Type-Options header" do
|
|
66
|
-
get '/'
|
|
67
|
-
expect(@env['X-Content-Type-Options']).to eq("nosniff")
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "sets the X-Permitted-Cross-Domain-Policies" do
|
|
71
|
-
get '/'
|
|
72
|
-
expect(@env['X-Permitted-Cross-Domain-Policies']).to eq("none")
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
context "using IE" do
|
|
76
|
-
it "sets the X-Content-Type-Options header" do
|
|
77
|
-
@env['HTTP_USER_AGENT'] = "Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0"
|
|
78
|
-
get '/'
|
|
79
|
-
expect(@env['X-Content-Type-Options']).to eq("nosniff")
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
# This controller is meant to be something that inherits config from application controller
|
|
4
|
-
# all values are defaulted because no initializer is configured, and the values in app controller
|
|
5
|
-
# only provide csp => false
|
|
6
|
-
|
|
7
|
-
describe ThingsController, :type => :controller do
|
|
8
|
-
describe "headers" do
|
|
9
|
-
it "sets the X-XSS-Protection header" do
|
|
10
|
-
get :index
|
|
11
|
-
expect(response.headers['X-XSS-Protection']).to eq('1; mode=block')
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "sets the X-Frame-Options header" do
|
|
15
|
-
get :index
|
|
16
|
-
expect(response.headers['X-Frame-Options']).to eq('SAMEORIGIN')
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "does not set CSP header" do
|
|
20
|
-
get :index
|
|
21
|
-
expect(response.headers['Content-Security-Policy-Report-Only']).to eq(nil)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
#mock ssl
|
|
25
|
-
it "sets the Strict-Transport-Security header" do
|
|
26
|
-
request.env['HTTPS'] = 'on'
|
|
27
|
-
get :index
|
|
28
|
-
expect(response.headers['Strict-Transport-Security']).to eq("max-age=315576000")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "sets the X-Download-Options header" do
|
|
32
|
-
get :index
|
|
33
|
-
expect(response.headers['X-Download-Options']).to eq('noopen')
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "sets the X-Content-Type-Options header" do
|
|
37
|
-
get :index
|
|
38
|
-
expect(response.headers['X-Content-Type-Options']).to eq("nosniff")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "sets the X-Permitted-Cross-Domain-Policies" do
|
|
42
|
-
get :index
|
|
43
|
-
expect(response.headers['X-Permitted-Cross-Domain-Policies']).to eq("none")
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context "using IE" do
|
|
47
|
-
it "sets the X-Content-Type-Options header" do
|
|
48
|
-
request.env['HTTP_USER_AGENT'] = "Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0"
|
|
49
|
-
get :index
|
|
50
|
-
expect(response.headers['X-Content-Type-Options']).to eq("nosniff")
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
|
|
3
|
-
#uncomment the following line to use spork with the debugger
|
|
4
|
-
#require 'spork/ext/ruby-debug'
|
|
5
|
-
|
|
6
|
-
# Spork.prefork do
|
|
7
|
-
# Loading more in this block will cause your tests to run faster. However,
|
|
8
|
-
# if you change any configuration or code from libraries loaded here, you'll
|
|
9
|
-
# need to restart spork for it take effect.
|
|
10
|
-
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
|
11
|
-
ENV["RAILS_ENV"] ||= 'test'
|
|
12
|
-
require File.expand_path("../../config/environment", __FILE__)
|
|
13
|
-
require 'rspec/rails'
|
|
14
|
-
# end
|
|
15
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
--color --format progress
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
== Welcome to Rails
|
|
2
|
-
|
|
3
|
-
Rails is a web-application framework that includes everything needed to create
|
|
4
|
-
database-backed web applications according to the Model-View-Control pattern.
|
|
5
|
-
|
|
6
|
-
This pattern splits the view (also called the presentation) into "dumb"
|
|
7
|
-
templates that are primarily responsible for inserting pre-built data in between
|
|
8
|
-
HTML tags. The model contains the "smart" domain objects (such as Account,
|
|
9
|
-
Product, Person, Post) that holds all the business logic and knows how to
|
|
10
|
-
persist themselves to a database. The controller handles the incoming requests
|
|
11
|
-
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
|
12
|
-
and directing data to the view.
|
|
13
|
-
|
|
14
|
-
In Rails, the model is handled by what's called an object-relational mapping
|
|
15
|
-
layer entitled Active Record. This layer allows you to present the data from
|
|
16
|
-
database rows as objects and embellish these data objects with business logic
|
|
17
|
-
methods. You can read more about Active Record in
|
|
18
|
-
link:files/vendor/rails/activerecord/README.html.
|
|
19
|
-
|
|
20
|
-
The controller and view are handled by the Action Pack, which handles both
|
|
21
|
-
layers by its two parts: Action View and Action Controller. These two layers
|
|
22
|
-
are bundled in a single package due to their heavy interdependence. This is
|
|
23
|
-
unlike the relationship between the Active Record and Action Pack that is much
|
|
24
|
-
more separate. Each of these packages can be used independently outside of
|
|
25
|
-
Rails. You can read more about Action Pack in
|
|
26
|
-
link:files/vendor/rails/actionpack/README.html.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
== Getting Started
|
|
30
|
-
|
|
31
|
-
1. At the command prompt, create a new Rails application:
|
|
32
|
-
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
|
33
|
-
|
|
34
|
-
2. Change directory to <tt>myapp</tt> and start the web server:
|
|
35
|
-
<tt>cd myapp; rails server</tt> (run with --help for options)
|
|
36
|
-
|
|
37
|
-
3. Go to http://localhost:3000/ and you'll see:
|
|
38
|
-
"Welcome aboard: You're riding Ruby on Rails!"
|
|
39
|
-
|
|
40
|
-
4. Follow the guidelines to start developing your application. You can find
|
|
41
|
-
the following resources handy:
|
|
42
|
-
|
|
43
|
-
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
|
44
|
-
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
== Debugging Rails
|
|
48
|
-
|
|
49
|
-
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
|
50
|
-
will help you debug it and get it back on the rails.
|
|
51
|
-
|
|
52
|
-
First area to check is the application log files. Have "tail -f" commands
|
|
53
|
-
running on the server.log and development.log. Rails will automatically display
|
|
54
|
-
debugging and runtime information to these files. Debugging info will also be
|
|
55
|
-
shown in the browser on requests from 127.0.0.1.
|
|
56
|
-
|
|
57
|
-
You can also log your own messages directly into the log file from your code
|
|
58
|
-
using the Ruby logger class from inside your controllers. Example:
|
|
59
|
-
|
|
60
|
-
class WeblogController < ActionController::Base
|
|
61
|
-
def destroy
|
|
62
|
-
@weblog = Weblog.find(params[:id])
|
|
63
|
-
@weblog.destroy
|
|
64
|
-
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
The result will be a message in your log file along the lines of:
|
|
69
|
-
|
|
70
|
-
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
|
71
|
-
|
|
72
|
-
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
|
73
|
-
|
|
74
|
-
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
|
75
|
-
several books available online as well:
|
|
76
|
-
|
|
77
|
-
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
|
78
|
-
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
|
79
|
-
|
|
80
|
-
These two books will bring you up to speed on the Ruby language and also on
|
|
81
|
-
programming in general.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
== Debugger
|
|
85
|
-
|
|
86
|
-
Debugger support is available through the debugger command when you start your
|
|
87
|
-
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
|
88
|
-
execution at any point in the code, investigate and change the model, and then,
|
|
89
|
-
resume execution! You need to install ruby-debug to run the server in debugging
|
|
90
|
-
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
|
91
|
-
|
|
92
|
-
class WeblogController < ActionController::Base
|
|
93
|
-
def index
|
|
94
|
-
@posts = Post.all
|
|
95
|
-
debugger
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
So the controller will accept the action, run the first line, then present you
|
|
100
|
-
with a IRB prompt in the server window. Here you can do things like:
|
|
101
|
-
|
|
102
|
-
>> @posts.inspect
|
|
103
|
-
=> "[#<Post:0x14a6be8
|
|
104
|
-
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
|
105
|
-
#<Post:0x14a6620
|
|
106
|
-
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
|
107
|
-
>> @posts.first.title = "hello from a debugger"
|
|
108
|
-
=> "hello from a debugger"
|
|
109
|
-
|
|
110
|
-
...and even better, you can examine how your runtime objects actually work:
|
|
111
|
-
|
|
112
|
-
>> f = @posts.first
|
|
113
|
-
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
|
114
|
-
>> f.
|
|
115
|
-
Display all 152 possibilities? (y or n)
|
|
116
|
-
|
|
117
|
-
Finally, when you're ready to resume execution, you can enter "cont".
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
== Console
|
|
121
|
-
|
|
122
|
-
The console is a Ruby shell, which allows you to interact with your
|
|
123
|
-
application's domain model. Here you'll have all parts of the application
|
|
124
|
-
configured, just like it is when the application is running. You can inspect
|
|
125
|
-
domain models, change values, and save to the database. Starting the script
|
|
126
|
-
without arguments will launch it in the development environment.
|
|
127
|
-
|
|
128
|
-
To start the console, run <tt>rails console</tt> from the application
|
|
129
|
-
directory.
|
|
130
|
-
|
|
131
|
-
Options:
|
|
132
|
-
|
|
133
|
-
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
|
134
|
-
made to the database.
|
|
135
|
-
* Passing an environment name as an argument will load the corresponding
|
|
136
|
-
environment. Example: <tt>rails console production</tt>.
|
|
137
|
-
|
|
138
|
-
To reload your controllers and models after launching the console run
|
|
139
|
-
<tt>reload!</tt>
|
|
140
|
-
|
|
141
|
-
More information about irb can be found at:
|
|
142
|
-
link:http://www.rubycentral.org/pickaxe/irb.html
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
== dbconsole
|
|
146
|
-
|
|
147
|
-
You can go to the command line of your database directly through <tt>rails
|
|
148
|
-
dbconsole</tt>. You would be connected to the database with the credentials
|
|
149
|
-
defined in database.yml. Starting the script without arguments will connect you
|
|
150
|
-
to the development database. Passing an argument will connect you to a different
|
|
151
|
-
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
|
152
|
-
PostgreSQL and SQLite 3.
|
|
153
|
-
|
|
154
|
-
== Description of Contents
|
|
155
|
-
|
|
156
|
-
The default directory structure of a generated Ruby on Rails application:
|
|
157
|
-
|
|
158
|
-
|-- app
|
|
159
|
-
| |-- assets
|
|
160
|
-
| |-- images
|
|
161
|
-
| |-- javascripts
|
|
162
|
-
| `-- stylesheets
|
|
163
|
-
| |-- controllers
|
|
164
|
-
| |-- helpers
|
|
165
|
-
| |-- mailers
|
|
166
|
-
| |-- models
|
|
167
|
-
| `-- views
|
|
168
|
-
| `-- layouts
|
|
169
|
-
|-- config
|
|
170
|
-
| |-- environments
|
|
171
|
-
| |-- initializers
|
|
172
|
-
| `-- locales
|
|
173
|
-
|-- db
|
|
174
|
-
|-- doc
|
|
175
|
-
|-- lib
|
|
176
|
-
| `-- tasks
|
|
177
|
-
|-- log
|
|
178
|
-
|-- public
|
|
179
|
-
|-- script
|
|
180
|
-
|-- test
|
|
181
|
-
| |-- fixtures
|
|
182
|
-
| |-- functional
|
|
183
|
-
| |-- integration
|
|
184
|
-
| |-- performance
|
|
185
|
-
| `-- unit
|
|
186
|
-
|-- tmp
|
|
187
|
-
| |-- cache
|
|
188
|
-
| |-- pids
|
|
189
|
-
| |-- sessions
|
|
190
|
-
| `-- sockets
|
|
191
|
-
`-- vendor
|
|
192
|
-
|-- assets
|
|
193
|
-
`-- stylesheets
|
|
194
|
-
`-- plugins
|
|
195
|
-
|
|
196
|
-
app
|
|
197
|
-
Holds all the code that's specific to this particular application.
|
|
198
|
-
|
|
199
|
-
app/assets
|
|
200
|
-
Contains subdirectories for images, stylesheets, and JavaScript files.
|
|
201
|
-
|
|
202
|
-
app/controllers
|
|
203
|
-
Holds controllers that should be named like weblogs_controller.rb for
|
|
204
|
-
automated URL mapping. All controllers should descend from
|
|
205
|
-
ApplicationController which itself descends from ActionController::Base.
|
|
206
|
-
|
|
207
|
-
app/models
|
|
208
|
-
Holds models that should be named like post.rb. Models descend from
|
|
209
|
-
ActiveRecord::Base by default.
|
|
210
|
-
|
|
211
|
-
app/views
|
|
212
|
-
Holds the template files for the view that should be named like
|
|
213
|
-
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
|
214
|
-
eRuby syntax by default.
|
|
215
|
-
|
|
216
|
-
app/views/layouts
|
|
217
|
-
Holds the template files for layouts to be used with views. This models the
|
|
218
|
-
common header/footer method of wrapping views. In your views, define a layout
|
|
219
|
-
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
|
220
|
-
Inside default.html.erb, call <% yield %> to render the view using this
|
|
221
|
-
layout.
|
|
222
|
-
|
|
223
|
-
app/helpers
|
|
224
|
-
Holds view helpers that should be named like weblogs_helper.rb. These are
|
|
225
|
-
generated for you automatically when using generators for controllers.
|
|
226
|
-
Helpers can be used to wrap functionality for your views into methods.
|
|
227
|
-
|
|
228
|
-
config
|
|
229
|
-
Configuration files for the Rails environment, the routing map, the database,
|
|
230
|
-
and other dependencies.
|
|
231
|
-
|
|
232
|
-
db
|
|
233
|
-
Contains the database schema in schema.rb. db/migrate contains all the
|
|
234
|
-
sequence of Migrations for your schema.
|
|
235
|
-
|
|
236
|
-
doc
|
|
237
|
-
This directory is where your application documentation will be stored when
|
|
238
|
-
generated using <tt>rake doc:app</tt>
|
|
239
|
-
|
|
240
|
-
lib
|
|
241
|
-
Application specific libraries. Basically, any kind of custom code that
|
|
242
|
-
doesn't belong under controllers, models, or helpers. This directory is in
|
|
243
|
-
the load path.
|
|
244
|
-
|
|
245
|
-
public
|
|
246
|
-
The directory available for the web server. Also contains the dispatchers and the
|
|
247
|
-
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
|
248
|
-
server.
|
|
249
|
-
|
|
250
|
-
script
|
|
251
|
-
Helper scripts for automation and generation.
|
|
252
|
-
|
|
253
|
-
test
|
|
254
|
-
Unit and functional tests along with fixtures. When using the rails generate
|
|
255
|
-
command, template test files will be generated for you and placed in this
|
|
256
|
-
directory.
|
|
257
|
-
|
|
258
|
-
vendor
|
|
259
|
-
External libraries that the application depends on. Also includes the plugins
|
|
260
|
-
subdirectory. If the app has frozen rails, those gems also go here, under
|
|
261
|
-
vendor/rails/. This directory is in the load path.
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env rake
|
|
2
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
3
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
4
|
-
|
|
5
|
-
require File.expand_path('../config/application', __FILE__)
|
|
6
|
-
|
|
7
|
-
Rails3212::Application.load_tasks
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
class OtherThingsController < ApplicationController
|
|
2
|
-
ensure_security_headers :csp => {:default_src => "'self'"}
|
|
3
|
-
def index
|
|
4
|
-
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def other_action
|
|
8
|
-
render :text => 'yooooo'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def secure_header_options_for(header, options)
|
|
12
|
-
if params[:action] == "other_action"
|
|
13
|
-
if header == :csp
|
|
14
|
-
options.merge(:style_src => "'self'")
|
|
15
|
-
end
|
|
16
|
-
else
|
|
17
|
-
options
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
index
|
|
File without changes
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../boot', __FILE__)
|
|
2
|
-
|
|
3
|
-
# Pick the frameworks you want:
|
|
4
|
-
require "action_controller/railtie"
|
|
5
|
-
require "sprockets/railtie"
|
|
6
|
-
|
|
7
|
-
if defined?(Bundler)
|
|
8
|
-
# If you precompile assets before deploying to production, use this line
|
|
9
|
-
Bundler.require(*Rails.groups(:assets => %w(development test)))
|
|
10
|
-
# If you want your assets lazily compiled in production, use this line
|
|
11
|
-
# Bundler.require(:default, :assets, Rails.env)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
module Rails3212
|
|
15
|
-
class Application < Rails::Application
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
Rails3212::Application.configure do
|
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
|
3
|
-
|
|
4
|
-
# The test environment is used exclusively to run your application's
|
|
5
|
-
# test suite. You never need to work with it otherwise. Remember that
|
|
6
|
-
# your test database is "scratch space" for the test suite and is wiped
|
|
7
|
-
# and recreated between test runs. Don't rely on the data there!
|
|
8
|
-
config.cache_classes = true
|
|
9
|
-
|
|
10
|
-
# Configure static asset server for tests with Cache-Control for performance
|
|
11
|
-
config.serve_static_assets = true
|
|
12
|
-
config.static_cache_control = "public, max-age=3600"
|
|
13
|
-
|
|
14
|
-
# Log error messages when you accidentally call methods on nil
|
|
15
|
-
config.whiny_nils = true
|
|
16
|
-
|
|
17
|
-
# Show full error reports and disable caching
|
|
18
|
-
config.consider_all_requests_local = true
|
|
19
|
-
config.action_controller.perform_caching = false
|
|
20
|
-
|
|
21
|
-
# Raise exceptions instead of rendering exception templates
|
|
22
|
-
config.action_dispatch.show_exceptions = false
|
|
23
|
-
|
|
24
|
-
# Disable request forgery protection in test environment
|
|
25
|
-
config.action_controller.allow_forgery_protection = false
|
|
26
|
-
|
|
27
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
|
28
|
-
# The :test delivery method accumulates sent emails in the
|
|
29
|
-
# ActionMailer::Base.deliveries array.
|
|
30
|
-
# config.action_mailer.delivery_method = :test
|
|
31
|
-
|
|
32
|
-
# Raise exception on mass assignment protection for Active Record models
|
|
33
|
-
# config.active_record.mass_assignment_sanitizer = :strict
|
|
34
|
-
|
|
35
|
-
# Print deprecation notices to the stderr
|
|
36
|
-
config.active_support.deprecation = :stderr
|
|
37
|
-
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe OtherThingsController, :type => :controller do
|
|
4
|
-
describe "headers" do
|
|
5
|
-
it "sets the X-XSS-Protection header" do
|
|
6
|
-
get :index
|
|
7
|
-
expect(response.headers['X-XSS-Protection']).to eq(SecureHeaders::XXssProtection::Constants::DEFAULT_VALUE)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "sets the X-Frame-Options header" do
|
|
11
|
-
get :index
|
|
12
|
-
expect(response.headers['X-Frame-Options']).to eq(SecureHeaders::XFrameOptions::Constants::DEFAULT_VALUE)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "sets the CSP header" do
|
|
16
|
-
get :index
|
|
17
|
-
expect(response.headers['Content-Security-Policy-Report-Only']).to eq("default-src 'self'; img-src 'self' data:;")
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "sets per-action values based on secure_header_options_for" do
|
|
21
|
-
# munges :style_src => self into policy
|
|
22
|
-
get :other_action
|
|
23
|
-
expect(response.headers['Content-Security-Policy-Report-Only']).to eq("default-src 'self'; img-src 'self' data:; style-src 'self';")
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
#mock ssl
|
|
27
|
-
it "sets the Strict-Transport-Security header" do
|
|
28
|
-
request.env['HTTPS'] = 'on'
|
|
29
|
-
get :index
|
|
30
|
-
expect(response.headers['Strict-Transport-Security']).to eq(SecureHeaders::StrictTransportSecurity::Constants::DEFAULT_VALUE)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "sets the X-Download-Options header" do
|
|
34
|
-
get :index
|
|
35
|
-
expect(response.headers['X-Download-Options']).to eq(SecureHeaders::XDownloadOptions::Constants::DEFAULT_VALUE)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "sets the X-Content-Type-Options header" do
|
|
39
|
-
get :index
|
|
40
|
-
expect(response.headers['X-Content-Type-Options']).to eq(SecureHeaders::XContentTypeOptions::Constants::DEFAULT_VALUE)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "sets the X-Permitted-Cross-Domain-Policies" do
|
|
44
|
-
get :index
|
|
45
|
-
expect(response.headers['X-Permitted-Cross-Domain-Policies']).to eq("none")
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context "using IE" do
|
|
49
|
-
it "sets the X-Content-Type-Options header" do
|
|
50
|
-
request.env['HTTP_USER_AGENT'] = "Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0"
|
|
51
|
-
get :index
|
|
52
|
-
expect(response.headers['X-Content-Type-Options']).to eq(SecureHeaders::XContentTypeOptions::Constants::DEFAULT_VALUE)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|