angular_xss 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/test.yml +58 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +78 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +1 -0
- data/Gemfile.rails-3.2 +9 -0
- data/Gemfile.rails-3.2.lock +91 -0
- data/Gemfile.rails-4.2.haml-4 +8 -0
- data/Gemfile.rails-4.2.haml-4.lock +88 -0
- data/Gemfile.rails-4.2.haml-5 +8 -0
- data/Gemfile.rails-4.2.haml-5.lock +90 -0
- data/Gemfile.rails-5.1.haml-4 +8 -0
- data/Gemfile.rails-5.1.haml-4.lock +85 -0
- data/Gemfile.rails-5.1.haml-5 +8 -0
- data/Gemfile.rails-5.1.haml-5.lock +87 -0
- data/Gemfile.rails-6.1.haml-5 +8 -0
- data/Gemfile.rails-6.1.haml-5.lock +90 -0
- data/Gemfile.rails-7.0.haml-5 +8 -0
- data/Gemfile.rails-7.0.haml-5.lock +86 -0
- data/README.md +2 -1
- data/Rakefile +3 -66
- data/angular_xss.gemspec +1 -0
- data/lib/angular_xss/action_view.rb +2 -1
- data/lib/angular_xss/erb.rb +2 -1
- data/lib/angular_xss/haml.rb +27 -10
- data/lib/angular_xss/safe_buffer.rb +31 -6
- data/lib/angular_xss/version.rb +1 -1
- data/spec/{shared/tests → angular_xss}/erb_spec.rb +1 -1
- data/spec/{shared/tests → angular_xss}/haml_spec.rb +1 -1
- data/spec/{shared/tests → angular_xss}/safe_buffer_spec.rb +0 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/{shared/support → support}/engine_preventing_angular_xss.rb +14 -2
- data/spec/{shared/app_root/app/views/test → templates}/_test_erb.erb +0 -0
- data/spec/{shared/app_root/app/views/test → templates}/_test_haml.haml +5 -3
- metadata +82 -205
- data/.travis.yml +0 -15
- data/spec/rails-2.3/Gemfile +0 -12
- data/spec/rails-2.3/Gemfile.lock +0 -62
- data/spec/rails-2.3/Rakefile +0 -11
- data/spec/rails-2.3/app_root/config/boot.rb +0 -129
- data/spec/rails-2.3/app_root/config/database.yml +0 -4
- data/spec/rails-2.3/app_root/config/environment.rb +0 -14
- data/spec/rails-2.3/app_root/config/environments/test.rb +0 -28
- data/spec/rails-2.3/app_root/config/preinitializer.rb +0 -20
- data/spec/rails-2.3/app_root/config/routes.rb +0 -4
- data/spec/rails-2.3/app_root/lib/console_with_fixtures.rb +0 -4
- data/spec/rails-2.3/app_root/log/.gitignore +0 -1
- data/spec/rails-2.3/app_root/script/console +0 -7
- data/spec/rails-2.3/rcov.opts +0 -2
- data/spec/rails-2.3/spec/spec_helper.rb +0 -20
- data/spec/rails-2.3/spec.opts +0 -4
- data/spec/rails-3.2/.rspec +0 -2
- data/spec/rails-3.2/Gemfile +0 -10
- data/spec/rails-3.2/Gemfile.lock +0 -129
- data/spec/rails-3.2/Rakefile +0 -10
- data/spec/rails-3.2/app_root/.gitignore +0 -4
- data/spec/rails-3.2/app_root/config/application.rb +0 -32
- data/spec/rails-3.2/app_root/config/boot.rb +0 -13
- data/spec/rails-3.2/app_root/config/database.yml +0 -4
- data/spec/rails-3.2/app_root/config/environment.rb +0 -5
- data/spec/rails-3.2/app_root/config/environments/test.rb +0 -35
- data/spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails-3.2/app_root/config/initializers/inflections.rb +0 -10
- data/spec/rails-3.2/app_root/config/initializers/mime_types.rb +0 -5
- data/spec/rails-3.2/app_root/config/initializers/secret_token.rb +0 -7
- data/spec/rails-3.2/app_root/config/initializers/session_store.rb +0 -8
- data/spec/rails-3.2/app_root/config/routes.rb +0 -58
- data/spec/rails-3.2/app_root/lib/tasks/.gitkeep +0 -0
- data/spec/rails-3.2/app_root/log/.gitkeep +0 -0
- data/spec/rails-3.2/app_root/script/rails +0 -6
- data/spec/rails-3.2/rcov.opts +0 -2
- data/spec/rails-3.2/spec/spec_helper.rb +0 -20
- data/spec/rails-4.2/.rspec +0 -2
- data/spec/rails-4.2/Gemfile +0 -10
- data/spec/rails-4.2/Gemfile.lock +0 -157
- data/spec/rails-4.2/Rakefile +0 -10
- data/spec/rails-4.2/app_root/.gitignore +0 -4
- data/spec/rails-4.2/app_root/config/application.rb +0 -34
- data/spec/rails-4.2/app_root/config/boot.rb +0 -13
- data/spec/rails-4.2/app_root/config/database.yml +0 -4
- data/spec/rails-4.2/app_root/config/environment.rb +0 -5
- data/spec/rails-4.2/app_root/config/environments/test.rb +0 -35
- data/spec/rails-4.2/app_root/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails-4.2/app_root/config/initializers/inflections.rb +0 -10
- data/spec/rails-4.2/app_root/config/initializers/mime_types.rb +0 -5
- data/spec/rails-4.2/app_root/config/initializers/secret_token.rb +0 -7
- data/spec/rails-4.2/app_root/config/initializers/session_store.rb +0 -8
- data/spec/rails-4.2/app_root/config/routes.rb +0 -3
- data/spec/rails-4.2/app_root/lib/tasks/.gitkeep +0 -0
- data/spec/rails-4.2/app_root/log/.gitkeep +0 -0
- data/spec/rails-4.2/app_root/script/rails +0 -6
- data/spec/rails-4.2/rcov.opts +0 -2
- data/spec/rails-4.2/spec/spec_helper.rb +0 -27
- data/spec/shared/app_root/app/controllers/application_controller.rb +0 -2
- data/spec/shared/app_root/app/helpers/application_helper.rb +0 -3
- data/spec/shared/app_root/app/models/.gitkeep +0 -0
- data/spec/shared/app_root/config/database.yml +0 -4
- data/spec/shared/app_root/db/migrate/.gitkeep +0 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
angular_xss (0.4.1)
|
5
|
+
activesupport
|
6
|
+
haml (>= 3.1.5)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (6.1.3.2)
|
12
|
+
actionview (= 6.1.3.2)
|
13
|
+
activesupport (= 6.1.3.2)
|
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.3.2)
|
19
|
+
activesupport (= 6.1.3.2)
|
20
|
+
builder (~> 3.1)
|
21
|
+
erubi (~> 1.4)
|
22
|
+
rails-dom-testing (~> 2.0)
|
23
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
24
|
+
activesupport (6.1.3.2)
|
25
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
26
|
+
i18n (>= 1.6, < 2)
|
27
|
+
minitest (>= 5.1)
|
28
|
+
tzinfo (~> 2.0)
|
29
|
+
zeitwerk (~> 2.3)
|
30
|
+
builder (3.2.4)
|
31
|
+
concurrent-ruby (1.1.9)
|
32
|
+
crass (1.0.6)
|
33
|
+
diff-lcs (1.4.4)
|
34
|
+
erubi (1.10.0)
|
35
|
+
gemika (0.6.0)
|
36
|
+
haml (5.2.1)
|
37
|
+
temple (>= 0.8.0)
|
38
|
+
tilt
|
39
|
+
i18n (1.8.10)
|
40
|
+
concurrent-ruby (~> 1.0)
|
41
|
+
loofah (2.10.0)
|
42
|
+
crass (~> 1.0.2)
|
43
|
+
nokogiri (>= 1.5.9)
|
44
|
+
mini_portile2 (2.5.3)
|
45
|
+
minitest (5.14.4)
|
46
|
+
nokogiri (1.11.7)
|
47
|
+
mini_portile2 (~> 2.5.0)
|
48
|
+
racc (~> 1.4)
|
49
|
+
racc (1.5.2)
|
50
|
+
rack (2.2.3)
|
51
|
+
rack-test (1.1.0)
|
52
|
+
rack (>= 1.0, < 3)
|
53
|
+
rails-dom-testing (2.0.3)
|
54
|
+
activesupport (>= 4.2.0)
|
55
|
+
nokogiri (>= 1.6)
|
56
|
+
rails-html-sanitizer (1.3.0)
|
57
|
+
loofah (~> 2.3)
|
58
|
+
rake (13.0.3)
|
59
|
+
rspec (3.10.0)
|
60
|
+
rspec-core (~> 3.10.0)
|
61
|
+
rspec-expectations (~> 3.10.0)
|
62
|
+
rspec-mocks (~> 3.10.0)
|
63
|
+
rspec-core (3.10.1)
|
64
|
+
rspec-support (~> 3.10.0)
|
65
|
+
rspec-expectations (3.10.1)
|
66
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
+
rspec-support (~> 3.10.0)
|
68
|
+
rspec-mocks (3.10.2)
|
69
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
70
|
+
rspec-support (~> 3.10.0)
|
71
|
+
rspec-support (3.10.2)
|
72
|
+
temple (0.8.2)
|
73
|
+
tilt (2.0.10)
|
74
|
+
tzinfo (2.0.4)
|
75
|
+
concurrent-ruby (~> 1.0)
|
76
|
+
zeitwerk (2.4.2)
|
77
|
+
|
78
|
+
PLATFORMS
|
79
|
+
ruby
|
80
|
+
|
81
|
+
DEPENDENCIES
|
82
|
+
actionpack (~> 6.1)
|
83
|
+
angular_xss!
|
84
|
+
gemika
|
85
|
+
haml (~> 5)
|
86
|
+
rake
|
87
|
+
rspec
|
88
|
+
|
89
|
+
BUNDLED WITH
|
90
|
+
2.2.20
|
@@ -0,0 +1,86 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
angular_xss (0.4.1)
|
5
|
+
activesupport
|
6
|
+
haml (>= 3.1.5)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (7.0.0)
|
12
|
+
actionview (= 7.0.0)
|
13
|
+
activesupport (= 7.0.0)
|
14
|
+
rack (~> 2.0, >= 2.2.0)
|
15
|
+
rack-test (>= 0.6.3)
|
16
|
+
rails-dom-testing (~> 2.0)
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
18
|
+
actionview (7.0.0)
|
19
|
+
activesupport (= 7.0.0)
|
20
|
+
builder (~> 3.1)
|
21
|
+
erubi (~> 1.4)
|
22
|
+
rails-dom-testing (~> 2.0)
|
23
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
24
|
+
activesupport (7.0.0)
|
25
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
26
|
+
i18n (>= 1.6, < 2)
|
27
|
+
minitest (>= 5.1)
|
28
|
+
tzinfo (~> 2.0)
|
29
|
+
builder (3.2.4)
|
30
|
+
concurrent-ruby (1.1.9)
|
31
|
+
crass (1.0.6)
|
32
|
+
diff-lcs (1.4.4)
|
33
|
+
erubi (1.10.0)
|
34
|
+
gemika (0.6.1)
|
35
|
+
haml (5.2.2)
|
36
|
+
temple (>= 0.8.0)
|
37
|
+
tilt
|
38
|
+
i18n (1.8.11)
|
39
|
+
concurrent-ruby (~> 1.0)
|
40
|
+
loofah (2.13.0)
|
41
|
+
crass (~> 1.0.2)
|
42
|
+
nokogiri (>= 1.5.9)
|
43
|
+
minitest (5.15.0)
|
44
|
+
nokogiri (1.12.5-x86_64-linux)
|
45
|
+
racc (~> 1.4)
|
46
|
+
racc (1.6.0)
|
47
|
+
rack (2.2.3)
|
48
|
+
rack-test (1.1.0)
|
49
|
+
rack (>= 1.0, < 3)
|
50
|
+
rails-dom-testing (2.0.3)
|
51
|
+
activesupport (>= 4.2.0)
|
52
|
+
nokogiri (>= 1.6)
|
53
|
+
rails-html-sanitizer (1.4.2)
|
54
|
+
loofah (~> 2.3)
|
55
|
+
rake (13.0.6)
|
56
|
+
rspec (3.10.0)
|
57
|
+
rspec-core (~> 3.10.0)
|
58
|
+
rspec-expectations (~> 3.10.0)
|
59
|
+
rspec-mocks (~> 3.10.0)
|
60
|
+
rspec-core (3.10.1)
|
61
|
+
rspec-support (~> 3.10.0)
|
62
|
+
rspec-expectations (3.10.1)
|
63
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
64
|
+
rspec-support (~> 3.10.0)
|
65
|
+
rspec-mocks (3.10.2)
|
66
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
+
rspec-support (~> 3.10.0)
|
68
|
+
rspec-support (3.10.3)
|
69
|
+
temple (0.8.2)
|
70
|
+
tilt (2.0.10)
|
71
|
+
tzinfo (2.0.4)
|
72
|
+
concurrent-ruby (~> 1.0)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
x86_64-linux
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
actionpack (~> 7.0)
|
79
|
+
angular_xss!
|
80
|
+
gemika
|
81
|
+
haml (~> 5)
|
82
|
+
rake
|
83
|
+
rspec
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
2.2.26
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
angular_xss [![Build Status](https://
|
1
|
+
angular_xss [![Build Status](https://github.com/makandra/angular_xss/workflows/Tests/badge.svg)](https://github.com/makandra/angular_xss/actions)
|
2
2
|
===========
|
3
3
|
|
4
4
|
When rendering AngularJS templates with a server-side templating engine like ERB or Haml it is easy to introduce XSS vulnerabilities. These vulnerabilities are enabled by AngularJS evaluating user-provided strings containing interpolation symbols (default symbols are `{{` and `}}`).
|
@@ -57,6 +57,7 @@ Development
|
|
57
57
|
|
58
58
|
- Fork the repository.
|
59
59
|
- Push your changes with specs. There is a Rails 3 test application in `spec/app_root` if you need to test integration with a live Rails app.
|
60
|
+
- You may run single tests with a specified Rails version via `BUNDLE_GEMFILE=Gemfile.rails-7.0.haml-5 bundle exec rspec ./spec/angular_xss`
|
60
61
|
- Send a pull request.
|
61
62
|
|
62
63
|
|
data/Rakefile
CHANGED
@@ -1,70 +1,7 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'bundler/gem_tasks'
|
3
|
+
require 'gemika/tasks'
|
3
4
|
|
4
|
-
desc 'Default: Run all specs.'
|
5
|
-
task :default => 'all:spec'
|
6
|
-
|
7
|
-
|
8
|
-
namespace :travis do
|
9
|
-
|
10
|
-
desc 'Run tests on Travis CI'
|
11
|
-
task :run => ['slimgems', 'all:bundle:install', 'all:spec']
|
12
|
-
|
13
|
-
desc 'Install slimgems'
|
14
|
-
task :slimgems do
|
15
|
-
if RUBY_VERSION == '1.8.7'
|
16
|
-
system('gem install slimgems')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
namespace :all do
|
23
|
-
|
24
|
-
desc "Run specs on all spec apps"
|
25
|
-
task :spec do
|
26
|
-
success = true
|
27
|
-
for_each_directory_of('spec/**/Rakefile') do |directory|
|
28
|
-
env = "SPEC=../../#{ENV['SPEC']} " if ENV['SPEC']
|
29
|
-
success &= system("cd #{directory} && #{env} bundle exec rake spec")
|
30
|
-
end
|
31
|
-
fail "Tests failed" unless success
|
32
|
-
end
|
33
5
|
|
34
|
-
|
35
|
-
|
36
|
-
desc "Bundle all spec apps"
|
37
|
-
task :install do
|
38
|
-
for_each_directory_of('spec/**/Gemfile') do |directory|
|
39
|
-
Bundler.with_clean_env do
|
40
|
-
system("cd #{directory} && bundle install")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
desc "Update all gems, or a list of gem given by the GEM environment variable"
|
46
|
-
task :update do
|
47
|
-
for_each_directory_of('spec/**/Gemfile') do |directory|
|
48
|
-
Bundler.with_clean_env do
|
49
|
-
system("cd #{directory} && bundle update #{ENV['GEM']}")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def for_each_directory_of(path, &block)
|
59
|
-
Dir[path].sort.each do |rakefile|
|
60
|
-
directory = File.dirname(rakefile)
|
61
|
-
puts '', "\033[44m#{directory}\033[0m", ''
|
62
|
-
|
63
|
-
if (RUBY_VERSION == '1.8.7' && directory =~ /-4\.2$/) ||
|
64
|
-
(RUBY_VERSION != '1.8.7' && directory =~ /-2\.3$/)
|
65
|
-
puts "Skipping tests for Ruby #{RUBY_VERSION} since it is unsupported"
|
66
|
-
else
|
67
|
-
block.call(directory)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
6
|
+
desc 'Default: Run all specs.'
|
7
|
+
task :default => 'matrix:spec'
|
data/angular_xss.gemspec
CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.summary = 'Patches rails_xss and Haml so AngularJS interpolations are auto-escaped in unsafe strings.'
|
11
11
|
s.description = s.summary
|
12
12
|
s.license = 'MIT'
|
13
|
+
s.metadata = { 'rubygems_mfa_required' => 'true' }
|
13
14
|
|
14
15
|
s.files = `git ls-files`.split($\)
|
15
16
|
s.test_files = s.files.grep(%r{^spec/})
|
data/lib/angular_xss/erb.rb
CHANGED
@@ -12,7 +12,8 @@ ERB::Util.module_eval do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
alias_method :unwrapped_html_escape_without_escaping_angular_expressions, :unwrapped_html_escape
|
16
|
+
alias_method :unwrapped_html_escape, :unwrapped_html_escape_with_escaping_angular_expressions
|
16
17
|
|
17
18
|
singleton_class.send(:remove_method, :unwrapped_html_escape)
|
18
19
|
module_function :unwrapped_html_escape
|
data/lib/angular_xss/haml.rb
CHANGED
@@ -1,15 +1,32 @@
|
|
1
|
-
#
|
2
|
-
Haml::
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
s
|
8
|
-
|
9
|
-
|
1
|
+
# Haml 5.0 and 5.1 fall back to erb
|
2
|
+
if Haml::VERSION < '5'
|
3
|
+
# Use module_eval so we crash when Haml::Helpers has not yet been loaded.
|
4
|
+
Haml::Helpers.module_eval do
|
5
|
+
|
6
|
+
def html_escape_with_escaping_angular_expressions(s)
|
7
|
+
s = s.to_s
|
8
|
+
if s.html_safe?
|
9
|
+
s
|
10
|
+
else
|
11
|
+
html_escape_without_escaping_angular_expressions(AngularXss::Escaper.escape(s))
|
12
|
+
end
|
10
13
|
end
|
14
|
+
|
15
|
+
alias_method :html_escape_without_escaping_angular_expressions, :html_escape
|
16
|
+
alias_method :html_escape, :html_escape_with_escaping_angular_expressions
|
11
17
|
end
|
12
18
|
|
13
|
-
|
19
|
+
elsif Haml::VERSION >= '5.2'
|
20
|
+
Haml::Helpers.module_eval do
|
21
|
+
|
22
|
+
def html_escape_without_haml_xss_with_escaping_angular_expressions(s)
|
23
|
+
s = s.to_s
|
24
|
+
return s if s.html_safe?
|
14
25
|
|
26
|
+
html_escape_without_haml_xss_without_escaping_angular_expressions(AngularXss::Escaper.escape(s))
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :html_escape_without_haml_xss_without_escaping_angular_expressions, :html_escape_without_haml_xss
|
30
|
+
alias_method :html_escape_without_haml_xss, :html_escape_without_haml_xss_with_escaping_angular_expressions
|
31
|
+
end
|
15
32
|
end
|
@@ -1,19 +1,44 @@
|
|
1
|
+
##
|
2
|
+
# Monkey patch ActiveSupport::SafeBuffer to escape double braces from Angular
|
3
|
+
#
|
4
|
+
# Link to the original implementation without Angular XSS escaping:
|
5
|
+
# https://github.com/rails/rails/blob/7-0-stable/activesupport/lib/active_support/core_ext/string/output_safety.rb#L295
|
6
|
+
#
|
1
7
|
ActiveSupport::SafeBuffer.class_eval do
|
2
8
|
|
3
|
-
|
9
|
+
html_escape = :html_escape_interpolated_argument
|
10
|
+
|
11
|
+
if private_method_defined?(html_escape) || # Rails < 6.1
|
12
|
+
private_method_defined?(:"explicit_#{html_escape}") # Rails >= 6.1
|
4
13
|
|
5
14
|
private
|
6
15
|
|
7
|
-
def
|
8
|
-
if arg.html_safe?
|
16
|
+
def explicit_html_escape_interpolated_argument_with_angular_xss(arg)
|
17
|
+
if !html_safe? || arg.html_safe?
|
9
18
|
arg
|
10
19
|
else
|
11
|
-
|
20
|
+
explicit_html_escape_interpolated_argument_without_angular_xss(AngularXss::Escaper.escape(arg))
|
12
21
|
end
|
13
22
|
end
|
14
23
|
|
15
|
-
|
24
|
+
if private_method_defined?(html_escape)
|
25
|
+
alias_method :"explicit_#{html_escape}_without_angular_xss", html_escape
|
26
|
+
alias_method html_escape, :"explicit_#{html_escape}_with_angular_xss"
|
27
|
+
elsif private_method_defined?(:"explicit_#{html_escape}")
|
28
|
+
alias_method :"explicit_#{html_escape}_without_angular_xss", :"explicit_#{html_escape}"
|
29
|
+
alias_method :"explicit_#{html_escape}", :"explicit_#{html_escape}_with_angular_xss"
|
30
|
+
end
|
16
31
|
|
32
|
+
if private_method_defined?(:"implicit_#{html_escape}")
|
33
|
+
def implicit_html_escape_interpolated_argument_with_angular_xss(arg)
|
34
|
+
if !html_safe? || arg.html_safe?
|
35
|
+
arg
|
36
|
+
else
|
37
|
+
implicit_html_escape_interpolated_argument_without_angular_xss(AngularXss::Escaper.escape(arg))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
alias_method :"implicit_#{html_escape}_without_angular_xss", :"implicit_#{html_escape}"
|
41
|
+
alias_method :"implicit_#{html_escape}", :"implicit_#{html_escape}_with_angular_xss"
|
42
|
+
end
|
17
43
|
end
|
18
|
-
|
19
44
|
end
|
data/lib/angular_xss/version.rb
CHANGED
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'active_support/all'
|
3
|
+
require 'action_dispatch'
|
4
|
+
require 'action_view'
|
5
|
+
|
6
|
+
begin
|
7
|
+
# Rails 3.2
|
8
|
+
require 'rails'
|
9
|
+
rescue LoadError
|
10
|
+
# Rails 4+
|
11
|
+
end
|
12
|
+
|
13
|
+
module Rails
|
14
|
+
def self.env
|
15
|
+
'test'.inquiry
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'haml'
|
20
|
+
require 'haml/template'
|
21
|
+
|
22
|
+
require 'angular_xss'
|
23
|
+
|
24
|
+
|
25
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
26
|
+
|
27
|
+
TEMPLATE_ROOT = Pathname.new(__dir__).join('templates')
|
28
|
+
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.mock_with :rspec do |c|
|
32
|
+
c.syntax = [:should, :expect]
|
33
|
+
end
|
34
|
+
config.expect_with :rspec do |c|
|
35
|
+
c.syntax = [:should, :expect]
|
36
|
+
end
|
37
|
+
end
|
@@ -1,6 +1,12 @@
|
|
1
|
-
shared_examples_for 'engine preventing Angular XSS' do
|
1
|
+
shared_examples_for 'engine preventing Angular XSS' do |partial:|
|
2
2
|
|
3
|
-
let(:
|
3
|
+
let(:path_set) { ActionView::LookupContext.new([TEMPLATE_ROOT]) }
|
4
|
+
|
5
|
+
if defined?(ActionView::VERSION) && ActionView::VERSION::MAJOR >= 6
|
6
|
+
let(:engine) { ActionView::Base.with_empty_template_cache.new(path_set, {}, nil) }
|
7
|
+
else
|
8
|
+
let(:engine) { ActionView::Base.new(path_set) }
|
9
|
+
end
|
4
10
|
|
5
11
|
let(:html) { engine.render(partial) }
|
6
12
|
|
@@ -72,4 +78,10 @@ shared_examples_for 'engine preventing Angular XSS' do
|
|
72
78
|
html.should_not include('{{unsafe}}')
|
73
79
|
end
|
74
80
|
|
81
|
+
it 'does not escape twice' do
|
82
|
+
escaped = AngularXss::Escaper.escape('{{')
|
83
|
+
double_escaped = AngularXss::Escaper.escape(escaped)
|
84
|
+
html.should_not include(double_escaped)
|
85
|
+
end
|
86
|
+
|
75
87
|
end
|
File without changes
|
@@ -29,7 +29,9 @@
|
|
29
29
|
%div{:class => '{{safe}}', :id => '{{safe}}'}
|
30
30
|
|
31
31
|
-# Compiled at runtime:
|
32
|
-
|
33
|
-
|
34
|
-
%div{:
|
32
|
+
- unsafe = '{{unsafe}}'
|
33
|
+
- safe = '{{safe}}'.html_safe
|
34
|
+
%div{:class => unsafe, :id => unsafe}
|
35
|
+
%div(bar="#{unsafe}")
|
36
|
+
%div{:foo => safe, :bar => unsafe}
|
35
37
|
{{safe}}
|