Skip to content

Commit 3c168a6

Browse files
authored
Fix security issues (#6040)
1 parent a0480b7 commit 3c168a6

21 files changed

Lines changed: 252 additions & 117 deletions

.github/actions/merge-artifacts/action.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@ runs:
3333
retention-days: 1
3434

3535
- name: Delete Artifacts
36+
env:
37+
SOURCE_NAME_PATTERN: ${{ inputs.source_name_pattern }}
38+
GITHUB_TOKEN: ${{ inputs.github_token }}
39+
GITHUB_REPOSITORY: ${{ github.repository }}
3640
run: |
37-
artifact_pattern="${{ inputs.source_name_pattern }}"
38-
TOKEN="${{ inputs.github_token }}"
41+
artifact_pattern="$SOURCE_NAME_PATTERN"
42+
TOKEN="$GITHUB_TOKEN"
3943
artifact_exists=true
4044
while [ "$artifact_exists" = true ]; do
4145
artifact_exists=false
4246
artifacts_response=$(curl -L \
4347
-H "Accept: application/vnd.github+json" \
4448
-H "Authorization: Bearer $TOKEN" \
4549
-H "X-GitHub-Api-Version: 2022-11-28" \
46-
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts?per_page=100")
50+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/artifacts?per_page=100")
4751
artifacts=$(echo $artifacts_response | jq -c '.artifacts[]')
4852
echo "Those are the artifacts : $artifacts"
4953
while read row; do
@@ -57,7 +61,7 @@ runs:
5761
-H "Accept: application/vnd.github+json" \
5862
-H "Authorization: Bearer $TOKEN" \
5963
-H "X-GitHub-Api-Version: 2022-11-28" \
60-
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/${artifact_id}"
64+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/artifacts/${artifact_id}"
6165
fi
6266
done <<< "$artifacts"
6367
done

.github/actions/package-nfpm/action.yml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,38 @@ runs:
6464
env:
6565
RPM_GPG_SIGNING_KEY_ID: ${{ inputs.rpm_gpg_signing_key_id }}
6666
RPM_GPG_SIGNING_PASSPHRASE: ${{ inputs.rpm_gpg_signing_passphrase }}
67+
INPUT_VERSION: ${{ inputs.version }}
68+
MAJOR_VERSION: ${{ inputs.major_version }}
69+
MINOR_VERSION: ${{ inputs.minor_version }}
70+
INPUT_RELEASE: ${{ inputs.release }}
71+
ARCH: ${{ inputs.arch }}
72+
PACKAGE_EXTENSION: ${{ inputs.package_extension }}
73+
DISTRIB: ${{ inputs.distrib }}
74+
STABILITY: ${{ inputs.stability }}
75+
PKG_DISTRIB_SEPARATOR: ${{ steps.parse-distrib.outputs.package_distrib_separator }}
76+
PKG_DISTRIB_NAME: ${{ steps.parse-distrib.outputs.package_distrib_name }}
77+
NFPM_FILE_PATTERN: ${{ inputs.nfpm_file_pattern }}
78+
COMMIT_HASH: ${{ inputs.commit_hash }}
6779
run: |
68-
if [ -z ${{ inputs.version }} ]; then
69-
export VERSION="${{ inputs.major_version }}.${{ inputs.minor_version }}"
70-
export MAJOR_VERSION="${{ inputs.major_version }}"
71-
export MINOR_VERSION="${{ inputs.minor_version }}"
72-
elif [ -z ${{ inputs.major_version }} ]; then
73-
export VERSION="${{ inputs.version }}"
80+
if [ -z $INPUT_VERSION ]; then
81+
export VERSION="${MAJOR_VERSION}.${MINOR_VERSION}"
82+
elif [ -z $MAJOR_VERSION ]; then
83+
export VERSION="${INPUT_VERSION}"
7484
export MAJOR_VERSION=$( echo $VERSION | cut -d "-" -f1 )
7585
export MINOR_VERSION=$( echo $VERSION | cut -d "-" -f2 )
7686
fi
77-
export RELEASE="${{ inputs.release }}"
78-
export ARCH="${{ inputs.arch }}"
87+
export RELEASE="${INPUT_RELEASE}"
7988
80-
if [ "${{ inputs.package_extension }}" = "rpm" ]; then
81-
export DIST=".${{ inputs.distrib }}"
89+
if [ "$PACKAGE_EXTENSION" = "rpm" ]; then
90+
export DIST=".$DISTRIB"
8291
export APACHE_USER="apache"
8392
export APACHE_GROUP="apache"
8493
else
8594
export DIST=""
86-
if [ "${{ inputs.stability }}" == "unstable" ] || [ "${{ inputs.stability }}" == "canary" ]; then
87-
export RELEASE="$RELEASE${{ steps.parse-distrib.outputs.package_distrib_separator }}${{ steps.parse-distrib.outputs.package_distrib_name }}"
95+
if [ "$STABILITY" == "unstable" ] || [ "$STABILITY" == "canary" ]; then
96+
export RELEASE="$RELEASE${PKG_DISTRIB_SEPARATOR}${PKG_DISTRIB_NAME}"
8897
else
89-
export RELEASE="1${{ steps.parse-distrib.outputs.package_distrib_separator }}${{ steps.parse-distrib.outputs.package_distrib_name }}"
98+
export RELEASE="1${PKG_DISTRIB_SEPARATOR}${PKG_DISTRIB_NAME}"
9099
fi
91100
export APACHE_USER="www-data"
92101
export APACHE_GROUP="www-data"
@@ -109,16 +118,16 @@ runs:
109118
export RPM_SIGNING_KEY_ID="$RPM_GPG_SIGNING_KEY_ID"
110119
export NFPM_RPM_PASSPHRASE="$RPM_GPG_SIGNING_PASSPHRASE"
111120
112-
for FILE in ${{ inputs.nfpm_file_pattern }}; do
121+
for FILE in $NFPM_FILE_PATTERN; do
113122
DIRNAME=$(dirname $FILE)
114123
BASENAME=$(basename $FILE)
115124
cd $DIRNAME
116125
sed -i "s/@APACHE_USER@/$APACHE_USER/g" $BASENAME
117126
sed -i "s/@APACHE_GROUP@/$APACHE_GROUP/g" $BASENAME
118-
sed -i "s/@COMMIT_HASH@/${{ inputs.commit_hash }}/g" $BASENAME
119-
nfpm package --config $BASENAME --packager ${{ inputs.package_extension }}
127+
sed -i "s/@COMMIT_HASH@/$COMMIT_HASH/g" $BASENAME
128+
nfpm package --config $BASENAME --packager $PACKAGE_EXTENSION
120129
cd -
121-
mv $DIRNAME/*.${{ inputs.package_extension }} ./
130+
mv $DIRNAME/*.$PACKAGE_EXTENSION ./
122131
done
123132
shell: bash
124133

.github/actions/parse-distrib/action.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,51 @@ runs:
2323
steps:
2424
- name: Parse distrib
2525
id: parse-distrib
26+
env:
27+
DISTRIB: ${{ inputs.distrib }}
2628
run: |
27-
if [[ "${{ inputs.distrib }}" == "alma8" || "${{ inputs.distrib }}" == "el8" ]]; then
29+
if [[ "$DISTRIB" == "alma8" || "$DISTRIB" == "el8" ]]; then
2830
PACKAGE_DISTRIB_SEPARATOR="."
2931
PACKAGE_DISTRIB_NAME="el8"
3032
PACKAGE_EXTENSION="rpm"
3133
DISTRIB_FAMILY="el"
32-
elif [[ "${{ inputs.distrib }}" == "alma9" || "${{ inputs.distrib }}" == "el9" ]]; then
34+
elif [[ "$DISTRIB" == "alma9" || "$DISTRIB" == "el9" ]]; then
3335
PACKAGE_DISTRIB_SEPARATOR="."
3436
PACKAGE_DISTRIB_NAME="el9"
3537
PACKAGE_EXTENSION="rpm"
3638
DISTRIB_FAMILY="el"
37-
elif [[ "${{ inputs.distrib }}" == "alma10" || "${{ inputs.distrib }}" == "el10" ]]; then
39+
elif [[ "$DISTRIB" == "alma10" || "$DISTRIB" == "el10" ]]; then
3840
PACKAGE_DISTRIB_SEPARATOR="."
3941
PACKAGE_DISTRIB_NAME="el10"
4042
PACKAGE_EXTENSION="rpm"
4143
DISTRIB_FAMILY="el"
42-
elif [[ "${{ inputs.distrib }}" == "bullseye" ]]; then
44+
elif [[ "$DISTRIB" == "bullseye" ]]; then
4345
PACKAGE_DISTRIB_SEPARATOR="+"
4446
PACKAGE_DISTRIB_NAME="deb11u1"
4547
PACKAGE_EXTENSION="deb"
4648
DISTRIB_FAMILY="debian"
47-
elif [[ "${{ inputs.distrib }}" == "bookworm" ]]; then
49+
elif [[ "$DISTRIB" == "bookworm" ]]; then
4850
PACKAGE_DISTRIB_SEPARATOR="+"
4951
PACKAGE_DISTRIB_NAME="deb12u1"
5052
PACKAGE_EXTENSION="deb"
5153
DISTRIB_FAMILY="debian"
52-
elif [[ "${{ inputs.distrib }}" == "trixie" ]]; then
54+
elif [[ "$DISTRIB" == "trixie" ]]; then
5355
PACKAGE_DISTRIB_SEPARATOR="+"
5456
PACKAGE_DISTRIB_NAME="deb13u1"
5557
PACKAGE_EXTENSION="deb"
5658
DISTRIB_FAMILY="debian"
57-
elif [[ "${{ inputs.distrib }}" == "jammy" ]]; then
59+
elif [[ "$DISTRIB" == "jammy" ]]; then
5860
PACKAGE_DISTRIB_SEPARATOR="-"
5961
PACKAGE_DISTRIB_NAME="0ubuntu.22.04"
6062
PACKAGE_EXTENSION="deb"
6163
DISTRIB_FAMILY="ubuntu"
62-
elif [[ "${{ inputs.distrib }}" == "noble" ]]; then
64+
elif [[ "$DISTRIB" == "noble" ]]; then
6365
PACKAGE_DISTRIB_SEPARATOR="-"
6466
PACKAGE_DISTRIB_NAME="0ubuntu.24.04"
6567
PACKAGE_EXTENSION="deb"
6668
DISTRIB_FAMILY="ubuntu"
6769
else
68-
echo "::error::Distrib ${{ inputs.distrib }} cannot be parsed"
70+
echo "::error::Distrib $DISTRIB cannot be parsed"
6971
exit 1
7072
fi
7173
echo "package_distrib_separator=$PACKAGE_DISTRIB_SEPARATOR" >> $GITHUB_OUTPUT

.github/actions/promote-to-stable/action.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ runs:
3030

3131
- name: Promote RPM packages to stable
3232
if: ${{ startsWith(inputs.distrib, 'el') }}
33+
env:
34+
DISTRIB: ${{ inputs.distrib }}
35+
MODULE: ${{ inputs.module }}
36+
STABILITY: ${{ inputs.stability }}
3337
run: |
3438
set -x
35-
echo "[DEBUG] - Distrib: ${{ inputs.distrib }}"
39+
echo "[DEBUG] - Distrib: $DISTRIB"
3640
3741
for ARCH in "noarch" "x86_64"; do
3842
echo "[DEBUG] - Get path of $ARCH testing artifacts to promote to stable."
39-
SRC_PATHS=$(jf rt s --include-dirs rpm-plugins/${{ inputs.distrib }}/testing/$ARCH/${{ inputs.module }}/*.rpm | jq -r '.[].path')
43+
SRC_PATHS=$(jf rt s --include-dirs rpm-plugins/$DISTRIB/testing/$ARCH/$MODULE/*.rpm | jq -r '.[].path')
4044
4145
if [[ ${SRC_PATHS[@]} ]]; then
4246
for SRC_PATH in ${SRC_PATHS[@]}; do
@@ -48,7 +52,7 @@ runs:
4852
fi
4953
5054
echo "[DEBUG] - Build $ARCH target path."
51-
TARGET_PATH="rpm-plugins/${{ inputs.distrib }}/${{ inputs.stability }}/$ARCH/RPMS/${{ inputs.module }}/"
55+
TARGET_PATH="rpm-plugins/$DISTRIB/$STABILITY/$ARCH/RPMS/$MODULE/"
5256
echo "[DEBUG] - Target path: $TARGET_PATH"
5357
5458
echo "[DEBUG] - Promoting $ARCH testing artifacts to stable."
@@ -67,20 +71,25 @@ runs:
6771

6872
- name: Promote DEB package to stable
6973
if: ${{ contains(fromJSON('["bullseye", "bookworm", "trixie", "jammy", "noble"]'), inputs.distrib) }}
74+
env:
75+
DISTRIB: ${{ inputs.distrib }}
76+
MODULE: ${{ inputs.module }}
77+
STABILITY: ${{ inputs.stability }}
78+
PKG_DISTRIB_NAME: ${{ steps.parse-distrib.outputs.package_distrib_name }}
7079
run: |
7180
set -eux
7281
73-
echo "[DEBUG] - Distrib: ${{ inputs.distrib }}"
74-
echo "[DEBUG] - Distrib: ${{ inputs.module }}"
82+
echo "[DEBUG] - Distrib: $DISTRIB"
83+
echo "[DEBUG] - Distrib: $MODULE"
7584
76-
if [[ "${{ inputs.distrib }}" == "jammy" || "${{ inputs.distrib }}" == "noble" ]]; then
85+
if [[ "$DISTRIB" == "jammy" || "$DISTRIB" == "noble" ]]; then
7786
repo="ubuntu-plugins"
7887
else
7988
repo="apt-plugins"
8089
fi
8190
8291
echo "[DEBUG] - Get path of testing DEB packages to promote to stable."
83-
SRC_PATHS=$(jf rt search --include-dirs $repo-testing/pool/${{ inputs.module }}/*${{ steps.parse-distrib.outputs.package_distrib_name }}*.deb | jq -r '.[].path')
92+
SRC_PATHS=$(jf rt search --include-dirs $repo-testing/pool/$MODULE/*${PKG_DISTRIB_NAME}*.deb | jq -r '.[].path')
8493
8594
if [[ ${SRC_PATHS[@]} ]]; then
8695
for SRC_PATH in ${SRC_PATHS[@]}; do
@@ -92,7 +101,7 @@ runs:
92101
fi
93102
94103
echo "[DEBUG] - Build target path."
95-
TARGET_PATH="$repo-${{ inputs.stability }}/pool/${{ inputs.module }}/"
104+
TARGET_PATH="$repo-$STABILITY/pool/$MODULE/"
96105
echo "[DEBUG] - Target path: $TARGET_PATH"
97106
98107
echo "[DEBUG] - Promoting DEB testing artifacts to stable."
@@ -101,10 +110,10 @@ runs:
101110
jf rt download $ARTIFACT --flat
102111
done
103112
104-
for ARTIFACT_DL in $(find . -maxdepth 1 -type f -name '*${{ steps.parse-distrib.outputs.package_distrib_name }}*.deb' -printf '%f\n'); do
113+
for ARTIFACT_DL in $(find . -maxdepth 1 -type f -name "*${PKG_DISTRIB_NAME}*.deb" -printf '%f\n'); do
105114
ARCH=$(echo $ARTIFACT_DL | cut -d '_' -f3 | cut -d '.' -f1)
106115
echo "[DEBUG] - Promoting (upload) $ARTIFACT_DL to stable $TARGET_PATH."
107-
jf rt upload "$ARTIFACT_DL" "$TARGET_PATH" --deb "${{ inputs.distrib }}/main/$ARCH"
116+
jf rt upload "$ARTIFACT_DL" "$TARGET_PATH" --deb "$DISTRIB/main/$ARCH"
108117
done
109118
rm -f *.deb
110119
shell: bash

.github/actions/release-sources/action.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,22 @@ runs:
3131
shell: bash
3232

3333
- name: Publish on download.centreon.com
34+
env:
35+
MODULE_NAME: ${{ inputs.module_name }}
36+
VERSION: ${{ inputs.version }}
37+
MODULE_DIRECTORY: ${{ inputs.module_directory }}
38+
BUCKET_DIRECTORY: ${{ inputs.bucket_directory }}
39+
TOKEN_DOWNLOAD: ${{ inputs.token_download_centreon_com }}
40+
RELEASE: ${{ inputs.release }}
3441
run: |
35-
SRC_FILE="${{ inputs.module_name }}-${{ inputs.version }}.tar.gz"
42+
SRC_FILE="${MODULE_NAME}-${VERSION}.tar.gz"
3643
37-
mv "${{ inputs.module_directory }}" "${{ inputs.module_name }}-${{ inputs.version }}"
38-
tar czf $SRC_FILE "${{ inputs.module_name }}-${{ inputs.version }}"
44+
mv "$MODULE_DIRECTORY" "${MODULE_NAME}-${VERSION}"
45+
tar czf $SRC_FILE "${MODULE_NAME}-${VERSION}"
3946
4047
SRC_HASH=$(md5sum $SRC_FILE | cut -d ' ' -f 1)
4148
SRC_SIZE=$(stat -c '%s' $SRC_FILE)
4249
43-
aws s3 cp --acl public-read "$SRC_FILE" "s3://centreon-download/public/${{ inputs.bucket_directory }}/$SRC_FILE"
44-
curl --fail "https://download.centreon.com/api/?token=${{ inputs.token_download_centreon_com }}&product=${{ inputs.module_name }}&release=${{ inputs.release }}&version=${{ inputs.version }}&extension=tar.gz&md5=$SRC_HASH&size=$SRC_SIZE&ddos=0&dryrun=0"
50+
aws s3 cp --acl public-read "$SRC_FILE" "s3://centreon-download/public/${BUCKET_DIRECTORY}/$SRC_FILE"
51+
curl --fail "https://download.centreon.com/api/?token=${TOKEN_DOWNLOAD}&product=${MODULE_NAME}&release=${RELEASE}&version=${VERSION}&extension=tar.gz&md5=$SRC_HASH&size=$SRC_SIZE&ddos=0&dryrun=0"
4552
shell: bash

.github/actions/test-cpan-libs/action.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ runs:
1717

1818
- if: ${{ inputs.package_extension == 'rpm' }}
1919
name: Install zstd, perl and Centreon repositories
20+
env:
21+
DISTRIB: ${{ inputs.distrib }}
2022
run: |
2123
dnf install -y zstd perl epel-release 'dnf-command(config-manager)' perl-App-cpanminus
2224
dnf config-manager --set-enabled powertools || true # alma 8
@@ -29,14 +31,14 @@ runs:
2931
{
3032
echo '[centreon-plugins-stable]'
3133
echo 'name=centreon plugins stable x86_64'
32-
echo "baseurl=https://packages.centreon.com/rpm-plugins/${{ inputs.distrib }}/stable/x86_64"
34+
echo "baseurl=https://packages.centreon.com/rpm-plugins/${DISTRIB}/stable/x86_64"
3335
echo 'enabled=1'
3436
echo 'gpgcheck=1'
3537
echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES'
3638
echo ''
3739
echo '[centreon-plugins-stable-noarch]'
3840
echo 'name=centreon plugins stable noarch'
39-
echo "baseurl=https://packages.centreon.com/rpm-plugins/${{ inputs.distrib }}/stable/noarch"
41+
echo "baseurl=https://packages.centreon.com/rpm-plugins/${DISTRIB}/stable/noarch"
4042
echo 'enabled=1'
4143
echo 'gpgcheck=1'
4244
echo 'gpgkey=https://yum-gpg.centreon.com/RPM-GPG-KEY-CES'
@@ -45,18 +47,20 @@ runs:
4547

4648
- if: ${{ inputs.package_extension == 'deb' }}
4749
name: Install zstd, perl and Centreon repositories
50+
env:
51+
DISTRIB: ${{ inputs.distrib }}
4852
run: |
4953
export DEBIAN_FRONTEND=noninteractive
5054
apt-get update
5155
apt-get install -y zstd perl wget gpg apt-utils procps build-essential cpanminus
5256
wget -O- https://apt-key.centreon.com | gpg --dearmor | tee /etc/apt/trusted.gpg.d/centreon.gpg > /dev/null 2>&1
5357
# Add Centreon stable repository so that pre-existing packaged dependencies are available
54-
if [[ "${{ inputs.distrib }}" == "jammy" || "${{ inputs.distrib }}" == "noble" ]]; then
58+
if [[ "$DISTRIB" == "jammy" || "$DISTRIB" == "noble" ]]; then
5559
repo="ubuntu-plugins-stable"
5660
else
5761
repo="apt-plugins-stable"
5862
fi
59-
echo "deb https://packages.centreon.com/$repo/ ${{ inputs.distrib }} main" | tee /etc/apt/sources.list.d/centreon-plugins.list
63+
echo "deb https://packages.centreon.com/$repo/ $DISTRIB main" | tee /etc/apt/sources.list.d/centreon-plugins.list
6064
# Avoid apt to clean packages cache directory
6165
rm -f /etc/apt/apt.conf.d/docker-clean
6266
apt-get update
@@ -71,8 +75,11 @@ runs:
7175

7276
- if: ${{ inputs.package_extension == 'rpm' }}
7377
name: Check packages installation / uninstallation
78+
env:
79+
DISTRIB: ${{ inputs.distrib }}
80+
ARCH: ${{ inputs.arch }}
7481
run: |
75-
error_log="install_error_${{ inputs.distrib }}_${{ inputs.arch }}.log"
82+
error_log="install_error_${DISTRIB}_${ARCH}.log"
7683
for package in ./*.rpm; do
7784
echo "Installing package: $package"
7885
# List dependencies, and remove version and comparison operators
@@ -120,11 +127,14 @@ runs:
120127

121128
- if: ${{ inputs.package_extension == 'deb' }}
122129
name: Check packages installation / uninstallation
130+
env:
131+
DISTRIB: ${{ inputs.distrib }}
132+
ARCH: ${{ inputs.arch }}
123133
run: |
124-
error_log="install_error_${{ inputs.distrib }}_${{ inputs.arch }}.log"
134+
error_log="install_error_${DISTRIB}_${ARCH}.log"
125135
for package in ./*.deb; do
126136
# If the debian package name ends with amd64 or arm64, we only install it if the tested architecture is the same, otherwise we skip it
127-
if [[ $package == *amd64.deb && ${{ inputs.arch }} != "amd64" || $package == *arm64.deb && ${{ inputs.arch }} != "arm64" ]]; then
137+
if [[ $package == *amd64.deb && $ARCH != "amd64" || $package == *arm64.deb && $ARCH != "arm64" ]]; then
128138
continue
129139
fi
130140
echo "Installing package: $package"
@@ -138,7 +148,7 @@ runs:
138148
echo "Dependency $dependency exists in debian repository."
139149
else
140150
# If the dependency has been built in the same workflow, install it
141-
for dependency_package in $(find . -maxdepth 1 -regex "\.\/${dependency}_[0-9].*all\.deb" -o -regex "\.\/${dependency}_[0-9].*${{ inputs.arch }}\.deb"); do
151+
for dependency_package in $(find . -maxdepth 1 -regex "\.\/${dependency}_[0-9].*all\.deb" -o -regex "\.\/${dependency}_[0-9].*${ARCH}\.deb"); do
142152
echo "Installing dependency: $dependency_package"
143153
error_output=$(apt-get install -y "$dependency_package" 2>&1) || { echo "$error_output" >> $error_log; echo "Error during installation of the dependency $dependency" >> $error_log; true; }
144154
done

.github/scripts/list-plugins-to-build-and-test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import json
4+
import os
45
import subprocess
56
import argparse
67
from pathlib import Path
@@ -47,7 +48,12 @@ def add_package_info(packaging_file, build=True, test=True):
4748
test_dependencies = []
4849
rpm_file = packaging_dir / 'rpm.json'
4950
if rpm_file.exists():
50-
with open(rpm_file) as rf:
51+
packaging_base = os.path.realpath("packaging")
52+
rpm_file_real = os.path.realpath(rpm_file)
53+
if os.path.commonpath([packaging_base, rpm_file_real]) != packaging_base:
54+
raise Exception("Invalid file path")
55+
fd = os.open(rpm_file_real, os.O_RDONLY | os.O_NOFOLLOW)
56+
with os.fdopen(fd) as rf:
5157
rpm_data = json.load(rf)
5258
test_dependencies = [dependency for dependency in rpm_data.get('dependencies', []) if dependency.lower().startswith('centreon-plugin-')]
5359
if packaging['pkg_name'] not in list_plugins:

0 commit comments

Comments
 (0)