Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModSecurity: Multipart parsing error: Multipart: Failed to create file: /tmp/modsecurity/tmp/ #269

Open
xBounceIT opened this issue Jul 5, 2024 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@xBounceIT
Copy link

After upgrading from container v3.3.5 to v4.3.0, this error has been appearing constantly.

It seems to be due to Apache not running as root, and the only fix i have found is to change the MODSEC_TMP_DIR variable from the default (which doesn't seem to work) to a more accessible "/tmp".

@fzipi
Copy link
Member

fzipi commented Jul 7, 2024

Sounds reasonable. Do you want to send a PR for this?

@fzipi fzipi added the bug Something isn't working label Jul 7, 2024
@theseion
Copy link
Contributor

theseion commented Jul 7, 2024

I think we need to fix the permissions of that directory instead, like we do for the other directories already.

@theseion
Copy link
Contributor

theseion commented Jul 7, 2024

Looking at the Dockerfile, the directory /tmp/modsecurity and all children should belong to httpd:httpd and there shouldn't be an issue with permissions at all.

@theseion
Copy link
Contributor

theseion commented Jul 7, 2024

I've checked and the permissions look ok. @xBounceIT, which tag are you using exactly?

@xBounceIT
Copy link
Author

I've checked and the permissions look ok. @xBounceIT, which tag are you using exactly?

Do you mean image tag? I am currently running 4.3.0-apache-202406090906

@theseion
Copy link
Contributor

theseion commented Jul 9, 2024

Yes, thanks.

@theseion
Copy link
Contributor

theseion commented Jul 9, 2024

Permissions and ownership look as expected. The init process is running as httpd, which is the same user that owns that directory.

How are you running the image? Can you please provide a way for us to recreate your issue? E.g., docker compose file or shell script.

@theseion theseion self-assigned this Jul 9, 2024
@xBounceIT
Copy link
Author

Sure, this is the docker compose and Dockerfile (since we use this image as a base and install modevasive too).

Docker compose:

version: '3'
services:
  waf:
    image: syncsec/waf:4.3.0
    container_name: waf
    hostname: waf
    restart: unless-stopped
    ports:
    - "443:8443"
    - "80:8080"
    environment:
    - TZ=Europe/Rome
    - PROXY=1
    - ERRORLOG=/var/log/apache2/error.log
    - MODSEC_AUDIT_LOG=/var/log/apache2/modsec/modsec_audit.log
    - MODSEC_DEBUG_LOG=/var/log/apache2/modsec/modsec_debug.log
    - MODSEC_DISABLE_BACKEND_COMPRESSION=On
    - MODSEC_PCRE_MATCH_LIMIT=1000000
    - ALLOWED_METHODS=GET HEAD POST OPTIONS PUT PROPFIND
    - ALLOWED_REQUEST_CONTENT_TYPE=|text/plain| |application/x-www-form-urlencoded| |multipart/form-data| |multipart/related| |text/xml| |application/xml| |application/soap+xml| |application/json| |application/cloudevents+json| |application/octet-stream|
    - SSL_OCSP_STAPLING=Off
    - SSL_PORT=8443
    - PORT=8080
    - MODSEC_TMP_DIR=/tmp
    volumes:
    # Custom vhosts
    - ./persistence/conf.d:/opt/conf.d
#    - ./persistence/conf.d/mod_security.conf:/etc/modsecurity.d/modsecurity.conf:ro
    # SSL
    - ./persistence/ssl:/usr/local/apache2/conf/ssl
    # Logs
    - ./persistence/log:/var/log/apache2

Dockerfile:

# Use the OWASP ModSecurity CRS base image with Apache
FROM owasp/modsecurity-crs:4.3.0-apache-202406090906

USER root

# Enable custom configurations
RUN sed -i 's/Include conf\/extra\/httpd-vhosts.conf/Include \/opt\/conf.d\/*.conf/' /usr/local/apache2/conf/httpd.conf

# Update package list, install necessary packages, and clean up
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y apache2-utils libapache2-mod-evasive && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

@theseion
Copy link
Contributor

theseion commented Jul 9, 2024

Looks like your issue is that you change the user to root. Because of that, httpd will run as root with workers spawned as www-data.
Resetting the user after installing the extra packages should do the trick:

USER httpd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants