Skip to content

Commit 1308d57

Browse files
authored
Merge pull request #285 from chef/ashiqueps/replace-io-with-file
Securiy fix - Polynomial regular expression used
2 parents bfdd526 + 5dbe548 commit 1308d57

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/chef-cli/policyfile_lock.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def cookbook_version_width
6464
end
6565
end
6666

67-
RUN_LIST_ITEM_FORMAT = /\Arecipe\[[^\s]+::[^\s]+\]\Z/
67+
RUN_LIST_ITEM_FORMAT = /\Arecipe\[([^:\s][^:\s]{0,254})::([^:\s][^:\s]{0,254})\]\Z/
6868

6969
def self.build(storage_config)
7070
lock = new(storage_config)

spec/shared/custom_generator_cookbook.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
FileUtils.cp_r(default_generator_cookbook_path, generator_cookbook_path)
108108

109109
# have to update metadata with the correct name
110-
IO.binwrite(metadata_file, "name 'a_generator_cookbook'")
110+
File.binwrite(metadata_file, "name 'a_generator_cookbook'")
111111
end
112112

113113
it "creates the new files" do

spec/unit/policyfile_lock_build_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,24 @@ def expect_hash_equal(actual, expected)
867867

868868
end
869869

870+
context "with invalid run list items" do
871+
it "detects invalid format in run list items with extra colons" do
872+
expect("recipe[cookbook:default::invalid]").not_to match(ChefCLI::PolicyfileLock::RUN_LIST_ITEM_FORMAT)
873+
end
874+
875+
it "detects invalid format when a run list item has no cookbook name" do
876+
expect("recipe[::recipe_name]").not_to match(ChefCLI::PolicyfileLock::RUN_LIST_ITEM_FORMAT)
877+
end
878+
879+
it "detects invalid format when a run list item has no recipe name" do
880+
expect("recipe[cookbook::]").not_to match(ChefCLI::PolicyfileLock::RUN_LIST_ITEM_FORMAT)
881+
end
882+
883+
it "validates proper recipe format correctly" do
884+
expect("recipe[cookbook::recipe_name]").to match(ChefCLI::PolicyfileLock::RUN_LIST_ITEM_FORMAT)
885+
end
886+
end
887+
870888
describe "building a policyfile lock from a policyfile compiler" do
871889

872890
include_context "setup git cookbooks"

0 commit comments

Comments
 (0)