# DOCKER-BP-026: Missing -y flag for dnf

> **Severity:** LOW | **CWE:** CWE-710

- **Language:** Docker
- **Category:** Best Practice
- **URL:** https://codepathfinder.dev/registry/docker/best-practice/DOCKER-BP-026
- **Detection:** `pathfinder scan --ruleset docker/DOCKER-BP-026 --project .`

## Description

dnf install without -y flag. Add -y for non-interactive builds.

## Vulnerable Code

```python
FROM fedora:39

# Bad: Missing -y flag
# Build will hang waiting for confirmation
RUN dnf install nginx
```

## Secure Code

```python
FROM fedora:39

# Good: Using -y flag for non-interactive installation
RUN dnf install -y nginx && \
    dnf clean all && \
    rm -rf /var/cache/dnf
```

## Detection Rule (Python SDK)

```python
from rules.container_decorators import dockerfile_rule
from rules.container_matchers import instruction
from rules.container_combinators import all_of


@dockerfile_rule(
    id="DOCKER-BP-026",
    name="Missing -y flag for dnf",
    severity="LOW",
    cwe="CWE-710",
    category="best-practice",
    tags="docker,dockerfile,dnf,package-manager,fedora,rhel,automation,ci-cd,build,best-practice,non-interactive",
    message="dnf install without -y flag. Add -y for non-interactive builds."
)
def missing_dnf_assume_yes():
    return all_of(
        instruction(type="RUN", contains="dnf install"),
        instruction(type="RUN", not_contains="-y")
    )
```

## How to Fix

- Review your Dockerfile to address the missing -y flag for dnf issue
- Follow Docker official best practices for image building
- Use docker build --check to validate Dockerfile syntax and best practices

## FAQ

**Q: Why does this rule flag missing -y flag for dnf?**

dnf install without -y flag. Add -y for non-interactive builds.

**Q: How do I fix this?**

Review the secure code example in the playground above and apply the recommended pattern to your Dockerfile or docker-compose.yml.

---

Source: https://codepathfinder.dev/registry/docker/best-practice/DOCKER-BP-026
Code Pathfinder — Open source, type-aware SAST with cross-file dataflow analysis
