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
cde7fe86
Commit
cde7fe86
authored
Jan 25, 2022
by
Kassio Borges
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Rubocop to check system file decompressing
parent
0a3578e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
0 deletions
+93
-0
rubocop/cop/file_decompression.rb
rubocop/cop/file_decompression.rb
+45
-0
spec/rubocop/cop/file_decompression_spec.rb
spec/rubocop/cop/file_decompression_spec.rb
+48
-0
No files found.
rubocop/cop/file_decompression.rb
0 → 100644
View file @
cde7fe86
# frozen_string_literal: true
module
RuboCop
module
Cop
# Check for symlinks when extracting files to avoid arbitrary file reading.
class
FileDecompression
<
RuboCop
::
Cop
::
Cop
MSG
=
<<~
EOF
While extracting files check for symlink to avoid arbitrary file reading.
https://gitlab.com/gitlab-com/gl-infra/production/-/issues/6132
EOF
def_node_matcher
:system?
,
<<~
PATTERN
(send {nil? | const} {:system | :exec | :spawn | :popen}
(str $_))
PATTERN
def_node_matcher
:subshell?
,
<<~
PATTERN
(xstr
(str $_))
PATTERN
FORBIDDEN_COMMANDS
=
%w[gunzip gzip zip tar]
.
freeze
def
on_xstr
(
node
)
subshell?
(
node
)
do
|
match
|
add_offense
(
node
,
message:
MSG
)
if
forbidden_command?
(
match
)
end
end
def
on_send
(
node
)
system
?(
node
)
do
|
match
|
add_offense
(
node
,
location: :expression
,
message:
MSG
)
if
forbidden_command?
(
match
)
end
end
private
def
forbidden_command?
(
cmd
)
FORBIDDEN_COMMANDS
.
any?
do
|
forbidden
|
cmd
.
match?
(
forbidden
)
end
end
end
end
end
spec/rubocop/cop/file_decompression_spec.rb
0 → 100644
View file @
cde7fe86
# frozen_string_literal: true
require
'fast_spec_helper'
require_relative
'../../../rubocop/cop/file_decompression'
RSpec
.
describe
RuboCop
::
Cop
::
FileDecompression
do
subject
(
:cop
)
{
described_class
.
new
}
it
'does not flag when using a system command not related to file decompression'
do
expect_no_offenses
(
'system("ls")'
)
end
described_class
::
FORBIDDEN_COMMANDS
.
map
{
[
_1
,
'^'
*
_1
.
length
]
}.
each
do
|
cmd
,
len
|
it
"flags the when using '
#{
cmd
}
' system command"
do
expect_offense
(
<<~
SOURCE
)
system('
#{
cmd
}
')
^^^^^^^^
#{
len
}
^^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
expect_offense
(
<<~
SOURCE
)
exec('
#{
cmd
}
')
^^^^^^
#{
len
}
^^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
expect_offense
(
<<~
SOURCE
)
Kernel.spawn('
#{
cmd
}
')
^^^^^^^^^^^^^^
#{
len
}
^^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
expect_offense
(
<<~
SOURCE
)
IO.popen('
#{
cmd
}
')
^^^^^^^^^^
#{
len
}
^^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
end
it
"flags the when using '
#{
cmd
}
' subshell command"
do
expect_offense
(
<<~
SOURCE
)
`
#{
cmd
}
`
^
#{
len
}
^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
expect_offense
(
<<~
SOURCE
)
%x(
#{
cmd
}
)
^^^
#{
len
}
^ While extracting files check for symlink to avoid arbitrary file reading[...]
SOURCE
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