Skip to content
代码片段 群组 项目
提交 14c3ede7 编辑于 作者: Nick Malcolm's avatar Nick Malcolm 提交者: Doug Stull
浏览文件

Clearly test the expectations around MAX_VERSION_LENGTH

上级 fdd0079d
No related branches found
No related tags found
无相关合并请求
...@@ -34,7 +34,7 @@ def verify_version!(version) ...@@ -34,7 +34,7 @@ def verify_version!(version)
end end
def different_version?(version) def different_version?(version)
Gem::Version.new(version) != Gem::Version.new(Gitlab::ImportExport.version) Gitlab::VersionInfo.parse(version) != Gitlab::VersionInfo.parse(Gitlab::ImportExport.version)
rescue StandardError => e rescue StandardError => e
Gitlab::Import::Logger.error( Gitlab::Import::Logger.error(
message: 'Import error', message: 'Import error',
......
...@@ -7,11 +7,14 @@ class VersionInfo ...@@ -7,11 +7,14 @@ class VersionInfo
attr_reader :major, :minor, :patch attr_reader :major, :minor, :patch
VERSION_REGEX = /(\d+)\.(\d+)\.(\d+)/.freeze VERSION_REGEX = /(\d+)\.(\d+)\.(\d+)/.freeze
# To mitigate ReDoS, limit the length of the version string we're
# willing to check
MAX_VERSION_LENGTH = 128
def self.parse(str, parse_suffix: false) def self.parse(str, parse_suffix: false)
if str.is_a?(self) if str.is_a?(self)
str str
elsif str && m = str.match(VERSION_REGEX) elsif str && str.length <= MAX_VERSION_LENGTH && m = str.match(VERSION_REGEX)
VersionInfo.new(m[1].to_i, m[2].to_i, m[3].to_i, parse_suffix ? m.post_match : nil) VersionInfo.new(m[1].to_i, m[2].to_i, m[3].to_i, parse_suffix ? m.post_match : nil)
else else
VersionInfo.new VersionInfo.new
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::ImportExport::VersionChecker do RSpec.describe Gitlab::ImportExport::VersionChecker, feature_category: :import do
include ImportExport::CommonUtil include ImportExport::CommonUtil
let!(:shared) { Gitlab::ImportExport::Shared.new(nil) } let!(:shared) { Gitlab::ImportExport::Shared.new(nil) }
......
...@@ -92,6 +92,8 @@ ...@@ -92,6 +92,8 @@
it { expect(described_class.parse("1.0.0-rc1-ee")).to eq(@v1_0_0) } it { expect(described_class.parse("1.0.0-rc1-ee")).to eq(@v1_0_0) }
it { expect(described_class.parse("git 1.0.0b1")).to eq(@v1_0_0) } it { expect(described_class.parse("git 1.0.0b1")).to eq(@v1_0_0) }
it { expect(described_class.parse("git 1.0b1")).not_to be_valid } it { expect(described_class.parse("git 1.0b1")).not_to be_valid }
it { expect(described_class.parse("1.1.#{'1' * described_class::MAX_VERSION_LENGTH}")).not_to be_valid }
it { expect(described_class.parse(nil)).not_to be_valid }
context 'with parse_suffix: true' do context 'with parse_suffix: true' do
let(:versions) do let(:versions) do
...@@ -182,4 +184,10 @@ ...@@ -182,4 +184,10 @@
it { expect(@v1_0_1.without_patch).to eq(@v1_0_0) } it { expect(@v1_0_1.without_patch).to eq(@v1_0_0) }
it { expect(@v1_0_1_rc1.without_patch).to eq(@v1_0_0) } it { expect(@v1_0_1_rc1.without_patch).to eq(@v1_0_0) }
end end
describe 'MAX_VERSION_LENGTH' do
subject { described_class::MAX_VERSION_LENGTH }
it { is_expected.to eq(128) }
end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册