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
3bfc08be
Commit
3bfc08be
authored
Aug 16, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix syntax highlight taking too long
Use Timeout to switch to plain rendering
parent
ba99dfcd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
1 deletion
+35
-1
changelogs/unreleased/security-2697-code-highlight-timeout.yml
...elogs/unreleased/security-2697-code-highlight-timeout.yml
+5
-0
lib/gitlab/highlight.rb
lib/gitlab/highlight.rb
+13
-1
spec/lib/gitlab/highlight_spec.rb
spec/lib/gitlab/highlight_spec.rb
+17
-0
No files found.
changelogs/unreleased/security-2697-code-highlight-timeout.yml
0 → 100644
View file @
3bfc08be
---
title
:
Set timeout for syntax highlighting
merge_request
:
author
:
type
:
security
lib/gitlab/highlight.rb
View file @
3bfc08be
module
Gitlab
class
Highlight
TIMEOUT_BACKGROUND
=
30
.
seconds
TIMEOUT_FOREGROUND
=
3
.
seconds
def
self
.
highlight
(
blob_name
,
blob_content
,
repository:
nil
,
plain:
false
)
new
(
blob_name
,
blob_content
,
repository:
repository
)
.
highlight
(
blob_content
,
continue:
false
,
plain:
plain
)
...
...
@@ -51,11 +54,20 @@ module Gitlab
end
def
highlight_rich
(
text
,
continue:
true
)
@formatter
.
format
(
lexer
.
lex
(
text
,
continue:
continue
),
tag:
lexer
.
tag
).
html_safe
tag
=
lexer
.
tag
tokens
=
lexer
.
lex
(
text
,
continue:
continue
)
Timeout
.
timeout
(
timeout_time
)
{
@formatter
.
format
(
tokens
,
tag:
tag
).
html_safe
}
rescue
Timeout
::
Error
=>
e
Gitlab
::
Sentry
.
track_exception
(
e
)
highlight_plain
(
text
)
rescue
highlight_plain
(
text
)
end
def
timeout_time
Sidekiq
.
server?
?
TIMEOUT_BACKGROUND
:
TIMEOUT_FOREGROUND
end
def
link_dependencies
(
text
,
highlighted_text
)
Gitlab
::
DependencyLinker
.
link
(
blob_name
,
text
,
highlighted_text
)
end
...
...
spec/lib/gitlab/highlight_spec.rb
View file @
3bfc08be
...
...
@@ -56,5 +56,22 @@ describe Gitlab::Highlight do
described_class
.
highlight
(
'file.name'
,
'Contents'
)
end
context
'timeout'
do
subject
{
described_class
.
new
(
'file.name'
,
'Contents'
)
}
it
'utilizes timeout for web'
do
expect
(
Timeout
).
to
receive
(
:timeout
).
with
(
described_class
::
TIMEOUT_FOREGROUND
).
and_call_original
subject
.
highlight
(
"Content"
)
end
it
'utilizes longer timeout for sidekiq'
do
allow
(
Sidekiq
).
to
receive
(
:server?
).
and_return
(
true
)
expect
(
Timeout
).
to
receive
(
:timeout
).
with
(
described_class
::
TIMEOUT_BACKGROUND
).
and_call_original
subject
.
highlight
(
"Content"
)
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