Skip to content

Commit 70d69a1

Browse files
Add our rails-angular-xss protection
Them gem patches Rails XSS protection methods with a replacement of `{{` strings with `{{ DOUBLE_LEFT_CURLY_BRACE }} `. `DOUBLE_LEFT_CURLY_BRACE` is defined by Angular to return `{{`, so we actually do execute the interpolation, but only to return the original string. More information: https://github.com/opf/rails-angular-xss angular/angular.js#5601
1 parent 5f34494 commit 70d69a1

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ gem 'rack-protection', git: 'https://github.com/finnlabs/rack-protection.git', r
9595
# https://github.com/kickstarter/rack-attack
9696
gem 'rack-attack'
9797

98+
# Patch Rails HTML whitelisting for Angular curly braces
99+
gem 'rails-angular-xss', github: 'opf/rails-angular-xss'
100+
98101
gem "syck", '~> 1.0.5', require: false
99102
gem 'gon', '~> 4.0'
100103

Gemfile.lock

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ GIT
2222
hashie (>= 1.2, < 4)
2323
rack (>= 1.0, < 3)
2424

25+
GIT
26+
remote: git://github.com/opf/rails-angular-xss.git
27+
revision: 11c068e623bbce09e35f41cf022d2204906e6a1f
28+
specs:
29+
rails-angular-xss (0.1.0)
30+
rails (>= 4.2.0, < 5.0)
31+
2532
GIT
2633
remote: git://github.com/why-el/svg-graph.git
2734
revision: e79abffa66639ab203d099250c5d2656a4ebf917
@@ -192,7 +199,7 @@ GEM
192199
coercible (1.0.0)
193200
descendants_tracker (~> 0.0.1)
194201
color-tools (1.3.0)
195-
concurrent-ruby (1.0.1)
202+
concurrent-ruby (1.0.2)
196203
crack (0.4.3)
197204
safe_yaml (~> 1.0.0)
198205
crowdin-api (0.4.0)
@@ -319,13 +326,13 @@ GEM
319326
tilt
320327
loofah (2.0.3)
321328
nokogiri (>= 1.5.9)
322-
mail (2.6.3)
323-
mime-types (>= 1.16, < 3)
329+
mail (2.6.4)
330+
mime-types (>= 1.16, < 4)
324331
method_source (0.8.2)
325332
mime-types (2.99.2)
326-
mini_portile2 (2.0.0)
333+
mini_portile2 (2.1.0)
327334
minisyntax (0.2.5)
328-
minitest (5.8.4)
335+
minitest (5.9.0)
329336
mixlib-shellout (2.1.0)
330337
multi_json (1.11.3)
331338
multi_test (0.1.2)
@@ -334,8 +341,9 @@ GEM
334341
net-ldap (0.14.0)
335342
netrc (0.11.0)
336343
newrelic_rpm (3.15.0.314)
337-
nokogiri (1.6.7.2)
338-
mini_portile2 (~> 2.0.0.rc2)
344+
nokogiri (1.6.8)
345+
mini_portile2 (~> 2.1.0)
346+
pkg-config (~> 1.1.7)
339347
oj (2.14.6)
340348
parallel (1.6.2)
341349
parallel_tests (2.4.1)
@@ -347,6 +355,7 @@ GEM
347355
rake (>= 0.8.1)
348356
pdf-core (0.6.1)
349357
pg (0.18.4)
358+
pkg-config (1.1.7)
350359
poltergeist (1.9.0)
351360
capybara (~> 2.1)
352361
cliver (~> 0.3.1)
@@ -427,7 +436,7 @@ GEM
427436
thor (>= 0.18.1, < 2.0)
428437
rainbow (2.1.0)
429438
raindrops (0.16.0)
430-
rake (11.1.1)
439+
rake (11.2.2)
431440
rb-readline (0.5.3)
432441
rdoc (4.2.2)
433442
json (~> 1.4)
@@ -646,6 +655,7 @@ DEPENDENCIES
646655
rack-test (~> 0.6.2)
647656
rack_session_access
648657
rails (~> 4.2.5)
658+
rails-angular-xss!
649659
rails-observers
650660
rails_12factor
651661
rails_autolink (~> 1.1.6)

frontend/app/init-app.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ opApp
110110
KeyboardShortcutService) {
111111
$http.defaults.headers.common.Accept = 'application/json';
112112

113+
// Set the escaping target of opening double curly braces
114+
// This is what returned by rails-angular-xss when it discoveres double open curly braces
115+
// See https://github.com/opf/rails-angular-xss for more information.
116+
$rootScope.DOUBLE_LEFT_CURLY_BRACE = '{{';
117+
113118
$rootScope.showNavigation =
114119
$window.sessionStorage.getItem('openproject:navigation-toggle') !==
115120
'collapsed';

0 commit comments

Comments
 (0)