Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

fix: added paths to dockerfiles and entrypoints to solve CWE-426 (#2241)

Lucas Oliveira97ce7c5bf88f
diff --git a/Dockerfile b/Dockerfile
index 9ed3ff2b8..9799d4083 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -132,7 +132,11 @@ RUN chmod +x /usr/share/opensearch/opensearch-entrypoint-wrapper.sh && \
USER opensearch
WORKDIR $OPENSEARCH_HOME
ENV JAVA_HOME=$OPENSEARCH_HOME/jdk
-ENV PATH=$PATH:$JAVA_HOME/bin:$OPENSEARCH_HOME/bin
+# CWE-426 fix: explicitly set PATH so system-owned directories are always resolved
+# first. App venv dirs are appended last so they cannot shadow system binaries.
+# Matches the ordering used by the upstream image but with system dirs promoted
+# to the front.
+ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/app-root/bin:/opt/app-root/src/bin:/opt/app-root/src/.local/bin:$JAVA_HOME/bin:$OPENSEARCH_HOME/bin
# Expose ports
EXPOSE 9200 9300 9600 9650
diff --git a/Dockerfile.backend b/Dockerfile.backend
index 5c039f6db..a4f47045a 100644
--- a/Dockerfile.backend
+++ b/Dockerfile.backend
@@ -25,7 +25,7 @@ RUN microdnf update -y \
&& python -m ensurepip --upgrade \
&& python -m pip install --no-cache-dir --upgrade "pip>=26.1" "setuptools>=78.1.1"
-ENV PATH="/root/.local/bin:$PATH" \
+ENV PATH="$PATH:/root/.local/bin" \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1
@@ -99,7 +99,9 @@ COPY --chown=appuser:appuser cloud_securityconfig/ ./cloud_securityconfig/
COPY --chown=appuser:appuser scripts/backend-entrypoint.sh /entrypoint.sh
ENV VIRTUAL_ENV=/app/.venv
-ENV PATH="/app/.venv/bin:$PATH"
+# CWE-426 fix: explicitly set PATH so system-owned directories are always resolved
+# first. App venv dirs are appended last so they cannot shadow system binaries.
+ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/.venv/bin:/opt/app-root/bin:/opt/app-root/src/bin:/opt/app-root/src/.local/bin
# Pre-create every directory the app writes to at runtime so they are owned
# by appuser in the image layer. When Docker/Podman mounts a host volume over
@@ -121,4 +123,4 @@ EXPOSE 8000
EXPOSE 8100
ENTRYPOINT ["/entrypoint.sh"]
-CMD ["python", "src/main.py"]
+CMD ["/app/.venv/bin/python", "src/main.py"]
\ No newline at end of file
diff --git a/Dockerfile.frontend b/Dockerfile.frontend
index fac19d56c..6ec7f193d 100644
--- a/Dockerfile.frontend
+++ b/Dockerfile.frontend
@@ -48,6 +48,12 @@ RUN microdnf update -y && microdnf clean all && rm -rf /var/cache/yum
ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1
+# CWE-426 fix: explicitly set PATH so system-owned directories are always resolved
+# first. App venv dirs are appended last so they cannot shadow system binaries.
+# Matches the ordering used by the upstream image but with system dirs promoted
+# to the front.
+ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/app-root/bin:/opt/app-root/src/bin:/opt/app-root/src/.local/bin
+
COPY --from=builder --chown=1001:0 /opt/app-root/src/package*.json ./
COPY --from=builder --chown=1001:0 /opt/app-root/src/stubs ./stubs
COPY --from=builder --chown=1001:0 /opt/app-root/src/.next ./.next
diff --git a/Dockerfile.langflow b/Dockerfile.langflow
index 0643100d3..f74719d57 100644
--- a/Dockerfile.langflow
+++ b/Dockerfile.langflow
@@ -40,6 +40,10 @@ ENV LANGFLOW_COMPONENTS_PATH=/app/custom_components
ENV LANGFLOW_COMPONENTS_INDEX_PATH=/app/component_index.json
ENV LANGFLOW_ALLOW_CUSTOM_COMPONENTS=false
+# CWE-426 fix: explicitly set PATH so system-owned directories are always resolved
+# first. App venv and ubi python dirs are appended last so they cannot shadow system binaries.
+ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/.venv/bin:/opt/app-root/bin:/opt/app-root/src/bin:/opt/app-root/src/.local/bin
+
EXPOSE 7860
ENTRYPOINT ["langflow-entrypoint"]
diff --git a/Dockerfile.langflow.dev b/Dockerfile.langflow.dev
index 156526540..ec78c53d7 100644
--- a/Dockerfile.langflow.dev
+++ b/Dockerfile.langflow.dev
@@ -64,5 +64,9 @@ ENV LANGFLOW_COMPONENTS_PATH=/app/custom_components
ENV LANGFLOW_COMPONENTS_INDEX_PATH=/app/component_index.json
ENV LANGFLOW_ALLOW_CUSTOM_COMPONENTS=false
+# CWE-426 fix: explicitly set PATH so system-owned directories are always resolved
+# first. App venv and ubi python dirs are appended last so they cannot shadow system binaries.
+ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/.venv/bin:/opt/app-root/bin:/opt/app-root/src/bin:/opt/app-root/src/.local/bin
+
# Start the backend server
CMD ["uv", "run", "langflow", "run", "--host", "0.0.0.0", "--port", "7860"]
diff --git a/kubernetes/operator/Dockerfile b/kubernetes/operator/Dockerfile
index c62a2e72c..37cc12a94 100644
--- a/kubernetes/operator/Dockerfile
+++ b/kubernetes/operator/Dockerfile
@@ -20,6 +20,9 @@ RUN microdnf install -y ca-certificates && \
microdnf clean all && \
rm -rf /var/cache/yum
+# CWE-426 fix: explicitly set PATH so system-owned directories are always resolved first.
+ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+
WORKDIR /
COPY --from=builder /workspace/manager .
diff --git a/scripts/backend-entrypoint.sh b/scripts/backend-entrypoint.sh
index 9f025cec2..e9827bb3a 100755
--- a/scripts/backend-entrypoint.sh
+++ b/scripts/backend-entrypoint.sh
@@ -22,7 +22,7 @@ if [ "$(id -u)" = "0" ]; then
2>/dev/null || true
exec runuser -u appuser -- env \
VIRTUAL_ENV=/app/.venv \
- PATH="/app/.venv/bin:$PATH" \
+ PATH="$PATH" \
"$@"
else
exec "$@"