Skip to content

Commit

Permalink
Fixed security issue with download 3rd party plugin (#2365)
Browse files Browse the repository at this point in the history
Added condition to avoid security issue according to GitHub's dependabot


![image](https://github.com/alshedivat/al-folio/assets/31376482/b470a83a-5038-48be-99a6-1cbf63de57bf)

---------

Signed-off-by: George Araujo <george.gcac@gmail.com>
  • Loading branch information
george-gca authored Apr 23, 2024
1 parent b315315 commit 06ca08c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion _plugins/download-3rd-party.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
require 'uri'

def download_file(url, dest)
# only try to download the file if url doesn't start with | for security reasons
if url.start_with?('|')
return
end

# create the directory if it doesn't exist
dir = File.dirname(dest)
unless File.directory?(dir)
Expand All @@ -30,11 +35,16 @@ def download_file(url, dest)
end

def download_fonts(url, dest)
# only try to download the file if url doesn't start with | for security reasons
if url.start_with?('|')
return
end

# only download fonts if the directory doesn't exist or is empty
unless File.directory?(dest) && !Dir.empty?(dest)
puts "Downloading fonts from #{url} to #{dest}"
# get available fonts from the url
doc = Nokogiri::HTML(URI().open(url, "User-Agent" => "Ruby/#{RUBY_VERSION}"))
doc = Nokogiri::HTML(URI.open(url, "User-Agent" => "Ruby/#{RUBY_VERSION}"))
doc.css('a').each do |link|
# get the file name from the url
file_name = link['href'].split('/').last.split('?').first
Expand All @@ -49,6 +59,11 @@ def download_fonts(url, dest)
end

def download_fonts_from_css(config, url, dest)
# only try to download the file if url doesn't start with | for security reasons
if url.start_with?('|')
return
end

# get the file name from the url
file_name = url.split('/').last.split('?').first

Expand Down

0 comments on commit 06ca08c

Please sign in to comment.