Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion common/lib/dependabot/dependency_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Operation
def initialize(name:, content:, directory: "/", type: "file",
support_file: false, symlink_target: nil,
content_encoding: ContentEncoding::UTF_8, deleted: false, operation: Operation::UPDATE)
@name = name
@name = sanitize_name(name)
@content = content
@directory = clean_directory(directory)
@symlink_target = symlink_target
Expand Down Expand Up @@ -114,5 +114,11 @@ def clean_directory(directory)
# Directory should always start with a `/`
directory.sub(%r{^/*}, "/")
end

def sanitize_name(name)
# Ensure name is a relative path without relative path traversal
path = Pathname.new(name).cleanpath
File.join(path.split.reject { |c| c.root? || c.to_s == "." || c.to_s == ".." })
end
end
end