T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/build-rpm.sh:6
- Finding
- RPM SPEC Injection Through Unvalidated Package Metadata<![CDATA[ ## Vulnerability Details **File Location**: `scripts/build-rpm.sh`, lines 6-15, 96-131, and 135-138 **Vulnerability Type**: Injection of attacker-controlled RPM macros and SPEC directives **Risk Level**: High ### Vulnerable Code ```bash SOURCE_DIR="${1:-.}" PACKAGE_NAME="${2:-$(basename "$SOURCE_DIR")}" VERSION="${3:-1.0.0}" RELEASE="${4:-1}" # Configurable build directory (default: ~/rpmbuild) RPM_BUILD_DIR="${RPM_BUILD_DIR:-$HOME/rpmbuild}" # Builder name for changelog (anonymized by default) RPM_BUILDER_NAME="${RPM_BUILDER_NAME:-OpenClaw Builder}" ``` ```bash generate_spec_file() { local SPEC_FILE="$RPM_BUILD_DIR/SPECS/${PACKAGE_NAME}.spec" log_info "Generating SPEC file: $SPEC_FILE" cat > "$SPEC_FILE" << EOF Name: ${PACKAGE_NAME} Version: ${VERSION} Release: ${RELEASE}%{?dist} Summary: ${PACKAGE_NAME} application License: MIT URL: https://example.com/${PACKAGE_NAME} Source0: %{name}-%{version}.tar.gz BuildRequires: gcc make Requires: glibc %description ${PACKAGE_NAME} - Built from source automatically %prep %setup -q %build %configure make %{?_smp_mflags} %install make install DESTDIR=%{buildroot} %files %defattr(-,root,root,-) %{_bindir}/${PACKAGE_NAME} %changelog * $(date +%a\ %b\ %d\ %Y) ${RPM_BUILDER_NAME} - ${VERSION}-${RELEASE} - Initial package build EOF log_info "SPEC file generated" echo "$SPEC_FILE" } ``` ```bash build_rpm() { local SPEC_FILE="$1" log_info "Building RPM package..." rpmbuild -ba "$SPEC_FILE" 2>&1 | tee "$RPM_BUILD_DIR/BUILDLOGS/${PACKAGE_NAME}-${VERSION}.log" ``` ### Technical Analysis The script accepts `PACKAGE_NAME`, `VERSION`, and `RELEASE` from positional arguments and `RPM_BUILDER_NAME` from the environment without validating their syntax. These values are inserted directly into an RPM SPEC file. Shell quoting around `cat > "$SPEC_FILE"` protects the destination filename from shell word ...[truncated 1820 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Apply strict allowlists before using package metadata: - Package name: permit only an explicitly supported subset such as ASCII letters, digits, `.`, `_`, `+`, and `-`. - Version and release: permit only RPM-compatible characters required by the project. - Reject `%`, newlines, carriage returns, control characters, whitespace, path separators, and shell metacharacters. 2. Validate `RPM_BUILDER_NAME` separately as display-only text. Reject newlines, control characters, and RPM macro introducers. 3. Fail closed when any value does not match the allowlist; do not attempt to remove individual dangerous characters from otherwise untrusted input. 4. Generate the SPEC file through a mechanism that explicitly escapes values for RPM syntax rather than relying on shell quoting. 5. Separate immutable SPEC structure from user-controlled descriptive metadata. Do not permit callers to provide raw SPEC fragments. 6. Run RPM builds as a dedicated, unprivileged account inside an isolated build environment such as a container or correctly configured `mock` environment. 7. Add regression tests covering percent-prefixed macros, multiline input, control characters, and malformed package metadata. ]]>
