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
abf83429
Commit
abf83429
authored
Mar 03, 2022
by
nobody
Committed by
Kerri Miller
Mar 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logs when potential path traversal attempt detected
parent
27be56f2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
0 deletions
+15
-0
lib/gitlab/utils.rb
lib/gitlab/utils.rb
+5
-0
spec/lib/gitlab/utils_spec.rb
spec/lib/gitlab/utils_spec.rb
+10
-0
No files found.
lib/gitlab/utils.rb
View file @
abf83429
...
...
@@ -5,6 +5,10 @@ module Gitlab
extend
self
PathTraversalAttackError
||=
Class
.
new
(
StandardError
)
private_class_method
def
logger
@logger
||=
Gitlab
::
AppLogger
end
# Ensure that the relative path will not traverse outside the base directory
# We url decode the path to avoid passing invalid paths forward in url encoded format.
# Also see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24223#note_284122580
...
...
@@ -16,6 +20,7 @@ module Gitlab
path_regex
=
%r{(
\A
(
\.
{1,2})
\z
|
\A\.\.
[/
\\
]|[/
\\
]
\.\.\z
|[/
\\
]
\.\.
[/
\\
]|
\n
)}
if
path
.
match?
(
path_regex
)
logger
.
warn
(
message:
"Potential path traversal attempt detected"
,
path:
"
#{
path
}
"
)
raise
PathTraversalAttackError
,
'Invalid path'
end
...
...
spec/lib/gitlab/utils_spec.rb
View file @
abf83429
...
...
@@ -53,6 +53,16 @@ RSpec.describe Gitlab::Utils do
expect
(
check_path_traversal!
(
'dir/.foo.rb'
)).
to
eq
(
'dir/.foo.rb'
)
end
it
'logs potential path traversal attempts'
do
expect
(
Gitlab
::
AppLogger
).
to
receive
(
:warn
).
with
(
message:
"Potential path traversal attempt detected"
,
path:
".."
)
expect
{
check_path_traversal!
(
'..'
)
}.
to
raise_error
(
/Invalid path/
)
end
it
'logs does nothing for a safe string'
do
expect
(
Gitlab
::
AppLogger
).
not_to
receive
(
:warn
).
with
(
message:
"Potential path traversal attempt detected"
,
path:
"dir/.foo.rb"
)
expect
(
check_path_traversal!
(
'dir/.foo.rb'
)).
to
eq
(
'dir/.foo.rb'
)
end
it
'does nothing for a non-string'
do
expect
(
check_path_traversal!
(
nil
)).
to
be_nil
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