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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
9ba554c8
Commit
9ba554c8
authored
Sep 27, 2018
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter system notes with public and private cross references
parent
bf37ff07
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
33 deletions
+80
-33
app/models/note.rb
app/models/note.rb
+15
-12
app/models/system_note_metadata.rb
app/models/system_note_metadata.rb
+5
-0
changelogs/unreleased/security-fix-leaking-private-project-namespace.yml
...leased/security-fix-leaking-private-project-namespace.yml
+5
-0
lib/banzai/object_renderer.rb
lib/banzai/object_renderer.rb
+1
-0
lib/banzai/redactor.rb
lib/banzai/redactor.rb
+7
-1
spec/models/note_spec.rb
spec/models/note_spec.rb
+47
-20
No files found.
app/models/note.rb
View file @
9ba554c8
...
...
@@ -38,10 +38,12 @@ class Note < ActiveRecord::Base
alias_attribute
:last_edited_at
,
:updated_at
alias_attribute
:last_edited_by
,
:updated_by
# Attribute containing rendered and redacted Markdown as generated by
# Banzai::ObjectRenderer.
# Number of user visible references as generated by Banzai::ObjectRenderer
attr_accessor
:redacted_note_html
# Total of all references as generated by Banzai::ObjectRenderer
attr_accessor
:total_reference_count
# An Array containing the number of visible references as generated by
# Banzai::ObjectRenderer
attr_accessor
:user_visible_reference_count
...
...
@@ -288,15 +290,7 @@ class Note < ActiveRecord::Base
end
def
cross_reference_not_visible_for?
(
user
)
cross_reference?
&&
!
has_referenced_mentionables?
(
user
)
end
def
has_referenced_mentionables?
(
user
)
if
user_visible_reference_count
.
present?
user_visible_reference_count
>
0
else
referenced_mentionables
(
user
).
any?
end
cross_reference?
&&
!
all_referenced_mentionables_allowed?
(
user
)
end
def
award_emoji?
...
...
@@ -466,9 +460,18 @@ class Note < ActiveRecord::Base
self
.
discussion_id
||=
discussion_class
.
discussion_id
(
self
)
end
def
all_referenced_mentionables_allowed?
(
user
)
if
user_visible_reference_count
.
present?
&&
total_reference_count
.
present?
# if they are not equal, then there are private/confidential references as well
user_visible_reference_count
>
0
&&
user_visible_reference_count
==
total_reference_count
else
referenced_mentionables
(
user
).
any?
end
end
def
force_cross_reference_regex_check?
return
unless
system
?
SystemNoteMetadata
::
TYPES_WITH_CROSS_REFERENCES
.
include?
(
system_note_metadata
&
.
action
)
system_note_metadata
&
.
cross_reference_types
&
.
include?
(
system_note_metadata
&
.
action
)
end
end
app/models/system_note_metadata.rb
View file @
9ba554c8
...
...
@@ -9,6 +9,7 @@ class SystemNoteMetadata < ActiveRecord::Base
TYPES_WITH_CROSS_REFERENCES
=
%w[
commit cross_reference
close duplicate
moved
]
.
freeze
ICON_TYPES
=
%w[
...
...
@@ -26,4 +27,8 @@ class SystemNoteMetadata < ActiveRecord::Base
def
icon_types
ICON_TYPES
end
def
cross_reference_types
TYPES_WITH_CROSS_REFERENCES
end
end
changelogs/unreleased/security-fix-leaking-private-project-namespace.yml
0 → 100644
View file @
9ba554c8
---
title
:
Properly filter private references from system notes
merge_request
:
author
:
type
:
security
lib/banzai/object_renderer.rb
View file @
9ba554c8
...
...
@@ -38,6 +38,7 @@ module Banzai
redacted_data
=
redacted
[
index
]
object
.
__send__
(
"redacted_
#{
attribute
}
_html="
,
redacted_data
[
:document
].
to_html
(
save_options
).
html_safe
)
# rubocop:disable GitlabSecurity/PublicSend
object
.
user_visible_reference_count
=
redacted_data
[
:visible_reference_count
]
if
object
.
respond_to?
(
:user_visible_reference_count
)
object
.
total_reference_count
=
redacted_data
[
:total_reference_count
]
if
object
.
respond_to?
(
:total_reference_count
)
end
end
...
...
lib/banzai/redactor.rb
View file @
9ba554c8
...
...
@@ -37,7 +37,13 @@ module Banzai
all_document_nodes
.
each
do
|
entry
|
nodes_for_document
=
entry
[
:nodes
]
doc_data
=
{
document:
entry
[
:document
],
visible_reference_count:
nodes_for_document
.
count
}
doc_data
=
{
document:
entry
[
:document
],
total_reference_count:
nodes_for_document
.
count
,
visible_reference_count:
nodes_for_document
.
count
}
metadata
<<
doc_data
nodes_for_document
.
each
do
|
node
|
...
...
spec/models/note_spec.rb
View file @
9ba554c8
...
...
@@ -231,33 +231,60 @@ describe Note do
let
(
:ext_proj
)
{
create
(
:project
,
:public
)
}
let
(
:ext_issue
)
{
create
(
:issue
,
project:
ext_proj
)
}
let
(
:note
)
do
create
:note
,
noteable:
ext_issue
,
project:
ext_proj
,
note:
"mentioned in issue
#{
private_issue
.
to_reference
(
ext_proj
)
}
"
,
system:
true
end
shared_examples
"checks references"
do
it
"returns true"
do
expect
(
note
.
cross_reference_not_visible_for?
(
ext_issue
.
author
)).
to
be_truthy
end
it
"returns tru
e"
do
expect
(
note
.
cross_reference_not_visible_for?
(
ext_issue
.
author
)).
to
be_truth
y
end
it
"returns fals
e"
do
expect
(
note
.
cross_reference_not_visible_for?
(
private_user
)).
to
be_fals
y
end
it
"returns false"
do
expect
(
note
.
cross_reference_not_visible_for?
(
private_user
)).
to
be_falsy
it
"returns false if user visible reference count set"
do
note
.
user_visible_reference_count
=
1
note
.
total_reference_count
=
1
expect
(
note
).
not_to
receive
(
:reference_mentionables
)
expect
(
note
.
cross_reference_not_visible_for?
(
ext_issue
.
author
)).
to
be_falsy
end
it
"returns true if ref count is 0"
do
note
.
user_visible_reference_count
=
0
expect
(
note
).
not_to
receive
(
:reference_mentionables
)
expect
(
note
.
cross_reference_not_visible_for?
(
ext_issue
.
author
)).
to
be_truthy
end
end
it
"returns false if user visible reference count set"
do
note
.
user_visible_reference_count
=
1
context
"when there is one reference in note"
do
let
(
:note
)
do
create
:note
,
noteable:
ext_issue
,
project:
ext_proj
,
note:
"mentioned in issue
#{
private_issue
.
to_reference
(
ext_proj
)
}
"
,
system:
true
end
expect
(
note
).
not_to
receive
(
:reference_mentionables
)
expect
(
note
.
cross_reference_not_visible_for?
(
ext_issue
.
author
)).
to
be_falsy
it_behaves_like
"checks references"
end
it
"returns true if ref count is 0"
do
note
.
user_visible_reference_count
=
0
context
"when there are two references in note"
do
let
(
:note
)
do
create
:note
,
noteable:
ext_issue
,
project:
ext_proj
,
note:
"mentioned in issue
#{
private_issue
.
to_reference
(
ext_proj
)
}
and "
\
"public issue
#{
ext_issue
.
to_reference
(
ext_proj
)
}
"
,
system:
true
end
it_behaves_like
"checks references"
expect
(
note
).
not_to
receive
(
:reference_mentionables
)
expect
(
note
.
cross_reference_not_visible_for?
(
ext_issue
.
author
)).
to
be_truthy
it
"returns true if user visible reference count set and there is a private reference"
do
note
.
user_visible_reference_count
=
1
note
.
total_reference_count
=
2
expect
(
note
).
not_to
receive
(
:reference_mentionables
)
expect
(
note
.
cross_reference_not_visible_for?
(
ext_issue
.
author
)).
to
be_truthy
end
end
end
...
...
@@ -269,7 +296,7 @@ describe Note do
end
context
'when the note might contain cross references'
do
SystemNoteMetadata
::
TYPES_WITH_CROSS_REFERENCES
.
each
do
|
type
|
SystemNoteMetadata
.
new
.
cross_reference_types
.
each
do
|
type
|
let
(
:note
)
{
create
(
:note
,
:system
)
}
let!
(
:metadata
)
{
create
(
:system_note_metadata
,
note:
note
,
action:
type
)
}
...
...
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