4 Commits

Author SHA1 Message Date
T. von Dein
d0e7c67d1b validate incoming config hashes, forbid comment, here-doc and include markers (#10)
fixes:
- #9

closes:
- CVE-2026-129820
- CVE-2026-129821

Co-authored-by: Thomas von Dein <tom@vondein.org>
Reviewed-on: https://codeberg.org/scip/Config-General/pulls/10
2026-11-17 13:50:23 +01:00
T. von Dein
9a3e72d7d1 fix release pipeline (#8) 2025-12-10 20:51:15 +01:00
d35ece0279 fix dist buil 2025-12-10 20:32:01 +01:00
d6dae42209 add release buil 2025-12-10 20:25:38 +01:00
5 changed files with 214 additions and 7 deletions

54
.woodpecker/release.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/bin/bash
# This is my own simple codeberg generic releaser. It takes to
# binaries to be uploaded as arguments and takes every other args from
# env. Works on tags or normal commits (push), tags must start with v.
set -e
die() {
echo $*
exit 1
}
if test -z "$DEPLOY_TOKEN"; then
die "token DEPLOY_TOKEN not set"
fi
git fetch --all
# determine current tag or commit hash
version="$CI_COMMIT_TAG"
previous=""
log=""
if test -z "$version"; then
version="${CI_COMMIT_SHA:0:6}"
log=$(git log -1 --oneline)
else
previous=$(git tag -l | grep -E "^v" | tac | grep -A1 "$version" | tail -1)
log=$(git log -1 --oneline "${previous}..${version}" | sed 's|^|- |g')
fi
# release body
printf "# Changes\n\n %s\n" "$log" > body.txt
# create the release
https --ignore-stdin --check-status -b -A bearer -a "$DEPLOY_TOKEN" POST \
"https://codeberg.org/api/v1/repos/${CI_REPO_OWNER}/${CI_REPO_NAME}/releases" \
tag_name="$version" name="Release $version" body=@body.txt > release.json
# we need the id to upload files
ID=$(jq -r .id < release.json)
if test -z "$ID"; then
cat release.json
die "failed to create release"
fi
# actually upload
for file in "$@"; do
https --ignore-stdin --check-status -A bearer -a "$DEPLOY_TOKEN" -f POST \
"https://codeberg.org/api/v1/repos/${CI_REPO_OWNER}/${CI_REPO_NAME}/releases/$ID/assets" \
"name=${file}" "attachment@${file}"
done

23
.woodpecker/release.yaml Normal file
View File

@@ -0,0 +1,23 @@
# build release
steps:
compile:
when:
event: [tag]
image: perl:5.43.5-slim-bookworm
commands:
- perl Makefile.PL
- make
- make dist
release:
image: alpine:latest
when:
event: [tag]
environment:
DEPLOY_TOKEN:
from_secret: DEPLOY_TOKEN
commands:
- apk update
- apk add --no-cache bash httpie jq git
- .woodpecker/release.sh Config-General-$CI_COMMIT_TAG.tar.gz

View File

@@ -5,7 +5,7 @@
# config values from a given file and
# return it as hash structure
#
# Copyright (c) 2000-2025 Thomas Linden <tlinden |AT| cpan.org>.
# Copyright (c) 2000-2026 Thomas Linden <tlinden |AT| cpan.org>.
# All Rights Reserved. Std. disclaimer applies.
# Licensed under the Artistic License 2.0.
#
@@ -20,7 +20,7 @@ use IO::File;
use FileHandle;
use File::Spec::Functions qw(splitpath file_name_is_absolute catfile catpath);
use File::Glob qw/:glob/;
use Data::Dumper;
# on debian with perl > 5.8.4 croak() doesn't work anymore without this.
# There is some require statement which dies 'cause it can't find Carp::Heavy,
@@ -32,7 +32,7 @@ use Carp::Heavy;
use Carp;
use Exporter;
$Config::General::VERSION = "2.67";
$Config::General::VERSION = "2.68";
use base qw(Exporter);
our @EXPORT_OK = qw(ParseConfig SaveConfig SaveConfigString);
@@ -286,6 +286,10 @@ sub _prepare {
$self->{ConfigFile} = delete $conf{-file};
}
if (exists $conf{-hash}) {
if (! $self->_validate_input_hash($conf{-hash})) {
croak "Config::General: supplied -hash hash contains invalid keys or values!\n";
}
$self->{ConfigHash} = delete $conf{-hash};
}
@@ -294,6 +298,10 @@ sub _prepare {
$self->{ConfigFile} = delete $conf{-ConfigFile};
}
if (exists $conf{-ConfigHash}) {
if (! $self->_validate_input_hash($conf{-ConfigHash})) {
croak "Config::General: supplied -ConfigHash hash contains invalid keys or values!\n";
}
$self->{ConfigHash} = delete $conf{-ConfigHash};
}
@@ -340,6 +348,10 @@ sub _prepare {
if (exists $conf{-DefaultConfig}) {
if ($conf{-DefaultConfig} && ref($conf{-DefaultConfig}) eq 'HASH') {
# copy the hashref so that it is not being modified by subsequent calls, fixes bug#142095
if (! $self->_validate_input_hash($conf{-DefaultConfig})) {
croak "Config::General: supplied -DefaultConfig hash contains invalid keys or values!\n";
}
$self->{DefaultConfig} = $self->_copy($conf{-DefaultConfig});
}
elsif ($conf{-DefaultConfig} && ref($conf{-DefaultConfig}) eq q()) {
@@ -1494,6 +1506,61 @@ sub _hashref {
}
}
sub _validate_input_hash {
#
# Checks if a given input hash contains invalid keys or values.
# Fixes https://codeberg.org/scip/Config-General/issues/9.
#
my($this, $hash) = @_;
if (ref($hash) eq '') {
return $this->_validate_input_hash_value($hash);
}
elsif (ref($hash) eq 'ARRAY') {
foreach my $sub (@{$hash}) {
return $this->_validate_input_hash($sub);
}
}
foreach my $key (keys %{$hash}) {
if (! $this->_validate_input_hash_value($key)) {
return 0;
}
if (ref($hash->{$key}) eq 'ARRAY') {
foreach my $sub (@{$hash->{$key}}) {
if (! $this->_validate_input_hash($sub)) {
return 0;
}
}
}
elsif(ref($hash->{$key}) eq 'HASH') {
if (! $this->_validate_input_hash($hash->{$key})) {
return 0;
}
}
else {
if (! $this->_validate_input_hash_value($hash->{$key})) {
return 0;
}
}
}
return 1;
}
sub _validate_input_hash_value {
#
# Checks a given key or value against a deny regex
my ($this, $value) = @_;
if ($value =~ /(<<|>>|\*\/|\/\*|#)/) {
return 0;
}
return 1;
}
#
# Procedural interface
@@ -2859,7 +2926,7 @@ I recommend you to read the following documents, which are supplied with Perl:
=head1 LICENSE AND COPYRIGHT
Copyright (c) 2000-2025 Thomas Linden
Copyright (c) 2000-2026 Thomas Linden
This library is free software; you can redistribute it and/or
modify it under the same terms of the Artistic License 2.0.
@@ -2888,7 +2955,7 @@ Thomas Linden <tlinden |AT| cpan.org>
=head1 VERSION
2.67
2.68
=cut

View File

@@ -1,7 +1,7 @@
#
# Makefile.PL - build file for Config::General
#
# Copyright (c) 2000-2022 Thomas Linden <tom@daemon.de>.
# Copyright (c) 2000-2026 Thomas Linden <tom@daemon.de>.
# All Rights Reserved. Std. disclaimer applies.
# Licensed under the Artistic License 2.0.
#

65
t/run.t
View File

@@ -8,7 +8,7 @@
use Data::Dumper;
use Test::More tests => 79;
use Test::More tests => 93;
#use Test::More qw(no_plan);
# ahem, we deliver the test code with a local copy of
@@ -801,3 +801,66 @@ my $conf59 = Config::General->new(
-AlwaysQuoteOutput => 1);
my $got59 = $conf59->save_string();
is_deeply \$expected59, \$got59, "quotes";
# test for CVE-2026-129820 and CVE-2026-129821 fixes
my $cvedefaults = [
{
"*/ foo" => 1,
},
{
"foo */" => 1,
},
{
"foo <<EOF foo" => 1,
},
{
"<<include nix>>" => 1,
},
{
"*/ foo" => "hans",
},
{
"foo # 1" => "nix",
},
{
"foo" => "*/ hier",
},
{
"foo" => "hier */",
},
{
"foo" => "<<EOF hier",
},
{
"foo" => "<<include hier>>",
},
{
"users" => {
"hans" => "*/ maddock",
},
},
{
"users" => {
"hans" => "maddock /*",
},
},
{
"users" => {
"hans" => "<<EOF maddock",
},
},
{
"list" => [
"ok",
"*/ foo",
]
}
];
foreach my $default (@{$cvedefaults}) {
eval {
my $conf60 = Config::General->new(-ConfigHash => $default) or die "$@";
};
ok($@, "cve check failed: " . Dumper($default));
}