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
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5fee1e3d
Commit
5fee1e3d
authored
Jun 01, 2021
by
Małgorzata Ksionek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sanitizing for name field
Changelog: security
parent
55bedf39
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
13 deletions
+31
-13
app/models/user.rb
app/models/user.rb
+11
-0
spec/features/snippets/notes_on_personal_snippets_spec.rb
spec/features/snippets/notes_on_personal_snippets_spec.rb
+0
-12
spec/models/user_spec.rb
spec/models/user_spec.rb
+20
-1
No files found.
app/models/user.rb
View file @
5fee1e3d
...
...
@@ -1256,12 +1256,23 @@ class User < ApplicationRecord
end
def
sanitize_attrs
sanitize_links
sanitize_name
end
def
sanitize_links
%i[skype linkedin twitter]
.
each
do
|
attr
|
value
=
self
[
attr
]
self
[
attr
]
=
Sanitize
.
clean
(
value
)
if
value
.
present?
end
end
def
sanitize_name
return
unless
self
.
name
self
.
name
=
self
.
name
.
gsub
(
%r{</?[^>]*>}
,
''
)
end
def
set_notification_email
if
notification_email
.
blank?
||
all_emails
.
exclude?
(
notification_email
)
self
.
notification_email
=
email
...
...
spec/features/snippets/notes_on_personal_snippets_spec.rb
View file @
5fee1e3d
...
...
@@ -65,18 +65,6 @@ RSpec.describe 'Comments on personal snippets', :js do
expect
(
page
).
to
have_content
(
user_name
)
end
end
context
'when the author name contains HTML'
do
let
(
:user_name
)
{
'<h1><a href="https://bad.link/malicious.exe" class="evil">Fake Content<img class="fake-icon" src="image.png"></a></h1>'
}
it
'renders the name as plain text'
do
visit
snippet_path
(
snippet
)
content
=
find
(
"#note_
#{
snippet_notes
[
0
].
id
}
.note-header-author-name"
).
text
expect
(
content
).
to
eq
user_name
end
end
end
context
'when submitting a note'
do
...
...
spec/models/user_spec.rb
View file @
5fee1e3d
...
...
@@ -2882,7 +2882,7 @@ RSpec.describe User do
end
describe
'#sanitize_attrs'
do
let
(
:user
)
{
build
(
:user
,
name:
'test & user'
,
skype:
'test&user'
)
}
let
(
:user
)
{
build
(
:user
,
name:
'test
<
& user'
,
skype:
'test&user'
)
}
it
'encodes HTML entities in the Skype attribute'
do
expect
{
user
.
sanitize_attrs
}.
to
change
{
user
.
skype
}.
to
(
'test&user'
)
...
...
@@ -2891,6 +2891,25 @@ RSpec.describe User do
it
'does not encode HTML entities in the name attribute'
do
expect
{
user
.
sanitize_attrs
}.
not_to
change
{
user
.
name
}
end
it
'sanitizes attr from html tags'
do
user
=
create
(
:user
,
name:
'<a href="//example.com">Test<a>'
,
twitter:
'<a href="//evil.com">https://twitter.com<a>'
)
expect
(
user
.
name
).
to
eq
(
'Test'
)
expect
(
user
.
twitter
).
to
eq
(
'https://twitter.com'
)
end
it
'sanitizes attr from js scripts'
do
user
=
create
(
:user
,
name:
'<script>alert("Test")</script>'
)
expect
(
user
.
name
).
to
eq
(
"alert(
\"
Test
\"
)"
)
end
it
'sanitizes attr from iframe scripts'
do
user
=
create
(
:user
,
name:
'User"><iframe src=javascript:alert()><iframe>'
)
expect
(
user
.
name
).
to
eq
(
'User">'
)
end
end
describe
'#starred?'
do
...
...
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