Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
02b88241
Commit
02b88241
authored
Jun 02, 2016
by
Gabriel Mazetto
Committed by
Robert Speicher
Jun 12, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix SVG whitelisting to allow namespaced attributes
parent
8d243f9b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
5 deletions
+66
-5
lib/gitlab/sanitizers/svg.rb
lib/gitlab/sanitizers/svg.rb
+18
-5
spec/lib/gitlab/sanitizers/svg_spec.rb
spec/lib/gitlab/sanitizers/svg_spec.rb
+48
-0
No files found.
lib/gitlab/sanitizers/svg.rb
View file @
02b88241
...
...
@@ -13,12 +13,11 @@ module Gitlab
unless
Whitelist
::
ALLOWED_ELEMENTS
.
include?
(
node
.
name
)
node
.
unlink
else
node
.
attributes
.
each
do
|
attr_name
,
attr
|
valid_attributes
=
Whitelist
::
ALLOWED_ATTRIBUTES
[
node
.
name
]
valid_attributes
=
Whitelist
::
ALLOWED_ATTRIBUTES
[
node
.
name
]
unless
valid_attributes
&&
valid_attributes
.
include?
(
attr_name
)
if
Whitelist
::
ALLOWED_DATA_ATTRIBUTES_IN_ELEMENTS
.
include?
(
node
.
name
)
&&
attr_name
.
start_with?
(
'data-'
)
node
.
attribute_nodes
.
each
do
|
attr
|
unless
valid_attributes
&&
valid_attributes
.
include?
(
attribute_name_with_namespace
(
attr
))
if
Whitelist
::
ALLOWED_DATA_ATTRIBUTES_IN_ELEMENTS
.
include?
(
node
.
name
)
&&
data_attribute?
(
attr
)
# Arbitrary data attributes are allowed. Verify that the attribute
# is a valid data attribute.
attr
.
unlink
unless
attr_name
=~
DATA_ATTR_PATTERN
...
...
@@ -29,6 +28,20 @@ module Gitlab
end
end
end
def
attribute_name_with_namespace
(
attr
)
if
attr
.
namespace
"
#{
attr
.
namespace
.
prefix
}
:
#{
attr
.
name
}
"
else
attr
.
name
end
end
private
def
data_attribute?
(
attr
)
attr
.
name
.
start_with?
(
'data-'
)
end
end
end
end
...
...
spec/lib/gitlab/sanitizers/svg_spec.rb
0 → 100644
View file @
02b88241
require
'spec_helper'
describe
Gitlab
::
Sanitizers
::
SVG
do
let
(
:scrubber
)
{
Gitlab
::
Sanitizers
::
SVG
::
Scrubber
.
new
}
let
(
:namespace
)
{
double
(
Nokogiri
::
XML
::
Namespace
,
prefix:
'xlink'
)
}
let
(
:namespaced_attr
)
{
double
(
Nokogiri
::
XML
::
Attr
,
name:
'href'
,
namespace:
namespace
)
}
context
'scrubber'
do
describe
'#scrub'
do
let
(
:invalid_element
)
{
double
(
Nokogiri
::
XML
::
Node
,
name:
'invalid'
)
}
let
(
:invalid_attribute
)
{
double
(
Nokogiri
::
XML
::
Attr
,
name:
'invalid'
,
namespace:
nil
)
}
let
(
:valid_element
)
{
double
(
Nokogiri
::
XML
::
Node
,
name:
'use'
)
}
it
'removes an invalid element'
do
expect
(
invalid_element
).
to
receive
(
:unlink
)
scrubber
.
scrub
(
invalid_element
)
end
it
'removes an invalid attribute'
do
allow
(
valid_element
).
to
receive
(
:attribute_nodes
)
{
[
invalid_attribute
]
}
expect
(
invalid_attribute
).
to
receive
(
:unlink
)
scrubber
.
scrub
(
valid_element
)
end
it
'accepts valid element'
do
allow
(
valid_element
).
to
receive
(
:attribute_nodes
)
{
[
namespaced_attr
]
}
expect
(
valid_element
).
not_to
receive
(
:unlink
)
scrubber
.
scrub
(
valid_element
)
end
it
'accepts valid namespaced attributes'
do
allow
(
valid_element
).
to
receive
(
:attribute_nodes
)
{
[
namespaced_attr
]
}
expect
(
namespaced_attr
).
not_to
receive
(
:unlink
)
scrubber
.
scrub
(
valid_element
)
end
end
describe
'#attribute_name_with_namespace'
do
it
'returns name with prefix when attribute is namespaced'
do
expect
(
scrubber
.
attribute_name_with_namespace
(
namespaced_attr
)).
to
eq
(
'xlink:href'
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment