|
2 | 2 | require 'yaml' |
3 | 3 | require 'json' |
4 | 4 |
|
| 5 | +# General rules: |
| 6 | +# - All the static parts of the expected URL are checked literally. |
| 7 | +# - Don't forget to escape dot (`.`) and other special characters when used literally. |
| 8 | +# - Each path component must begin with [\w], or a even more restrictive character set. |
| 9 | +# - Percent (`%`) shall not be allowed to avoid any percent encoding. |
| 10 | +WINDOWS_VERSIONS_URLS_REGEXPS = [ |
| 11 | + %r{^https://github\.com/oneclick/rubyinstaller2?/releases/download/\w[\w.-]*/\w[\w.-]*$}, |
| 12 | + %r{^https://github\.com/MSP-Greg/ruby-loco/releases/download/\w[\w.-]*/\w[\w.-]*$} |
| 13 | +].freeze |
| 14 | + |
| 15 | +WINDOWS_TOOLCHAIN_VERSIONS_URLS_REGEXPS = [ |
| 16 | + %r{^https://github\.com/oneclick/rubyinstaller/releases/download/devkit-4\.7\.2/DevKit-mingw64-64-4\.7\.2-20130224-1432-sfx\.exe$}, |
| 17 | + %r{^https://github\.com/ruby/setup-msys2-gcc/releases/download/\w[\w.-]*/\w[\w@.-]*$}, |
| 18 | + %r{^https://github\.com/ruby/setup-msys2-gcc/releases/latest/download/\w[\w@.-]*$} |
| 19 | +].freeze |
| 20 | + |
| 21 | +# Validate all the URLs in the versions json |
| 22 | +def validate(versions, allowed_urls_regexps) |
| 23 | + versions.values.flat_map(&:values).each do |url| |
| 24 | + if allowed_urls_regexps.none? { |regexp| regexp =~ url } |
| 25 | + raise SecurityError, "Unexpected URL: #{url}" |
| 26 | + end |
| 27 | + end |
| 28 | +end |
| 29 | + |
5 | 30 | min_requirements = ['~> 2.0.0', '~> 2.1.9', '>= 2.2.6'].map { |req| Gem::Requirement.new(req) } |
6 | 31 |
|
7 | 32 | url = 'https://raw.githubusercontent.com/oneclick/rubyinstaller.org-website/master/_data/downloads.yaml' |
|
48 | 73 | 'x64' => 'https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-ucrt.7z' |
49 | 74 | } |
50 | 75 |
|
| 76 | +validate(versions, WINDOWS_VERSIONS_URLS_REGEXPS) |
51 | 77 | File.binwrite 'windows-versions.json', "#{JSON.pretty_generate(versions)}\n" |
52 | 78 |
|
53 | 79 | base_url = 'https://github.com/ruby/setup-msys2-gcc/releases/latest/download/windows-toolchain.json' |
|
90 | 116 | end |
91 | 117 | end |
92 | 118 |
|
| 119 | +validate(versions, WINDOWS_TOOLCHAIN_VERSIONS_URLS_REGEXPS) |
93 | 120 | File.binwrite 'windows-toolchain-versions.json', "#{JSON.pretty_generate(versions)}\n" |
0 commit comments