Skip to content

Commit 601f681

Browse files
committed
fqdn_rotate: Don't use the value itself as part of the random seed
Previously, the random number generator was seeded with the array or string to be rotated in addition to any values specifically provided for seeding. This behavior is potentially insecure in that it allows an attacker who can modify the source data to choose the post-shuffle order.
1 parent a383705 commit 601f681

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

lib/puppet/parser/functions/fqdn_rotate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Puppet::Parser::Functions
1111
raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments " +
1212
"given (#{arguments.size} for 1)") if arguments.size < 1
1313

14-
value = arguments[0]
14+
value = arguments.shift
1515
require 'digest/md5'
1616

1717
unless value.is_a?(Array) || value.is_a?(String)

spec/acceptance/fqdn_rotate_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
EOS
3737

3838
apply_manifest(pp, :catch_failures => true) do |r|
39-
expect(r.stdout).to match(/fqdn_rotate is \["c", "d", "a", "b"\]/)
39+
expect(r.stdout).to match(/fqdn_rotate is \["d", "a", "b", "c"\]/)
4040
end
4141
end
4242
end

spec/functions/fqdn_rotate_spec.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
66
it { is_expected.to run.with_params(0).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) }
77
it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) }
8-
it {
9-
pending("Current implementation ignores parameters after the first.")
10-
is_expected.to run.with_params("one", "two").and_raise_error(Puppet::ParseError)
11-
}
128
it { is_expected.to run.with_params('').and_return('') }
139
it { is_expected.to run.with_params('a').and_return('a') }
1410

@@ -38,7 +34,7 @@
3834

3935
it "should use the Puppet::Util.deterministic_rand function" do
4036
if Puppet::Util.respond_to?(:deterministic_rand)
41-
Puppet::Util.expects(:deterministic_rand).with(113646079810780526294648115052177588845,4)
37+
Puppet::Util.expects(:deterministic_rand).with(44489829212339698569024999901561968770,4)
4238
fqdn_rotate("asdf")
4339
else
4440
skip 'Puppet::Util#deterministic_rand not available'

0 commit comments

Comments
 (0)