T09 · Insecure Skill Coding Practices
- Location
scripts/bake.sh:161- Finding
Predictable Container Temporary Files Can Expose Privileged Macaroons
- Content
View full analysis
Vulnerability Details
File Location:
scripts/bake.sh, lines 161-187 and 324-327
Vulnerability Type: Predictable temporary credential files and incomplete cleanup
Risk Level: MediumVulnerable code (inspection path, lines 161-187):
bash if [ -n "$CONTAINER" ]; then # The macaroon may be on the host or inside the container. If it # exists on the host, copy it into the container for inspection. if [ -f "$INSPECT" ]; then CONTAINER_TMP="/tmp/inspect-$(date +%s).macaroon" docker cp "$INSPECT" "$CONTAINER:$CONTAINER_TMP" INSPECT_PATH="$CONTAINER_TMP" elif docker exec "$CONTAINER" test -f "$INSPECT" 2>/dev/null; then INSPECT_PATH="$INSPECT" else echo "Error: Macaroon file not found: $INSPECT" >&2 exit 1 fi elif [ ! -f "$INSPECT" ]; then echo "Error: Macaroon file not found: $INSPECT" >&2 exit 1 else INSPECT_PATH="$INSPECT" fi echo "=== Macaroon: $(basename "$INSPECT") ===" echo "Path: $INSPECT" if [ -n "$CONTAINER" ]; then echo "Container: $CONTAINER" fi echo "" "${LNCLI_CMD[@]}" printmacaroon --macaroon_file "$INSPECT_PATH" # Clean up temporary copy if we created one. if [ -n "$CONTAINER" ] && [ -f "$INSPECT" ]; then docker exec "$CONTAINER" rm -f "$INSPECT_PATH" 2>/dev/null || true fiVulnerable code (baking path, lines 324-327):
bash CONTAINER_TMP="/tmp/baked-$(date +%s).macaroon" "${LNCLI_CMD[@]}" bakemacaroon "${PERMS[@]}" --save_to="$CONTAINER_TMP" docker cp "$CONTAINER:$CONTAINER_TMP" "$SAVE_TO" docker exec "$CONTAINER" rm -f "$CONTAINER_TMP"Technical Analysis
Macaroons are bearer credentials that may authorize payments, invoice management, channel administration, signing, or custom operations. The script stores these credentials under the container's shared
/tmpdirectory using filenames based only on `d ...[truncated 2261 chars]- Remediation
View remediation
Remediation Suggestions
- Create a private temporary directory inside the container using a cryptographically unpredictable mechanism such as
mktemp -d. - Set the temporary directory to mode
0700and generated credential files to mode0600before use. - Reject pre-existing files, symbolic links, and non-regular files. Ensure credential creation uses exclusive semantics where supported.
- Register cleanup immediately with an
EXIT,INT, andTERMtrap so temporary credentials are removed on success, command failure, interruption, or early exit. - Avoid a shared temporary directory where possible. Stream data securely or use a dedicated bind-mounted directory accessible only to the intended container user.
- Verify the ownership and permissions of the container-side credential before copying or inspecting it.
- Use distinct randomized temporary paths for concurrent executions to prevent collisions.
- Create a private temporary directory inside the container using a cryptographically unpredictable mechanism such as
