Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

5.4 KB
Raw Blame
worker_processes auto;
error_log /tmp/nginx_error.log warn;
pid /tmp/nginx.pid;

events {
    worker_connections 1024;
    use epoll;
    multi_accept on;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # Temp directories for non-root
    client_body_temp_path /tmp/client_temp;
    proxy_temp_path /tmp/proxy_temp;
    fastcgi_temp_path /tmp/fastcgi_temp;
    uwsgi_temp_path /tmp/uwsgi_temp;
    scgi_temp_path /tmp/scgi_temp;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /tmp/nginx_access.log main;

    # Performance
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    # Gzip compression
    gzip on;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_min_length 1024;
    gzip_types text/plain text/css text/xml text/javascript
               application/json application/javascript application/xml
               application/rss+xml application/atom+xml image/svg+xml;

    # Security
    server_tokens off;

    # Host-header allowlist — defends against DNS rebinding.
    # The CORSMiddleware on the API blocks cross-origin reads, but after a
    # DNS rebinding flip the browser treats the request as same-origin and
    # skips the CORS check entirely, so a server-side Host check is the
    # canonical defense. Without it, attacker JS on evil.com can drive a
    # victim's browser to POST /api/auth/register against a flowsint instance
    # bound to localhost or a LAN IP, planting attacker-controlled accounts.
    #
    # Default allowlist covers single-user local deploys (localhost / 127.0.0.1
    # / ::1, any port). When deploying on a network (see README "Deploy on a
    # network"), add the server hostname/IP below — and add the public
    # hostname too when fronting with a reverse proxy like Caddy.
    map $http_host $is_flowsint_host {
        default 0;
        "~*^localhost(:[0-9]+)?$"    1;
        "~*^127\.0\.0\.1(:[0-9]+)?$" 1;
        "~*^\[::1\](:[0-9]+)?$"      1;
        # "~*^flowsint\.example\.com$"   1;
        # "~*^192\.168\.1\.42(:[0-9]+)?$" 1;
    }

    server {
        listen 8080;
        server_name _;
        root /usr/share/nginx/html;
        index index.html;

        # Default-deny unknown Host headers (DNS rebinding defense).
        # See $is_flowsint_host map above for the allowlist.
        if ($is_flowsint_host = 0) {
            return 403;
        }

        # Security headers
        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header X-XSS-Protection "1; mode=block" always;
        add_header Referrer-Policy "strict-origin-when-cross-origin" always;

        # API reverse proxy — same-origin, no CORS needed.
        # Expects the API service to be reachable as "api:5001" on the compose network.
        # Uses system resolver (/etc/resolv.conf) — compatible with Docker and Podman.
        # Trade-off: hostname resolved once at startup; restart app if api IP changes.
        location /api/ {
            proxy_pass http://api:5001;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            # SSE support (event/chat streams)
            proxy_set_header Connection "";
            proxy_buffering off;
            proxy_cache off;
            proxy_read_timeout 3600s;
        }

        # Health check endpoint
        location /health {
            access_log off;
            return 200 "healthy\n";
            add_header Content-Type text/plain;
        }

        # Static assets with aggressive caching
        location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
            expires 1y;
            add_header Cache-Control "public, immutable";
            # Re-declare server-level security headers — nginx's add_header
            # inheritance is replace-all, not merge, so a location block that
            # sets any add_header drops every header set higher up.
            add_header X-Frame-Options "SAMEORIGIN" always;
            add_header X-Content-Type-Options "nosniff" always;
            add_header X-XSS-Protection "1; mode=block" always;
            add_header Referrer-Policy "strict-origin-when-cross-origin" always;
            access_log off;
        }

        # SPA fallback - serve index.html for all routes
        location / {
            try_files $uri $uri/ /index.html;
        }

        # No cache for index.html
        location = /index.html {
            expires -1;
            add_header Cache-Control "no-store, no-cache, must-revalidate";
            # Re-declare server-level security headers (see static-assets
            # location above for why).
            add_header X-Frame-Options "SAMEORIGIN" always;
            add_header X-Content-Type-Options "nosniff" always;
            add_header X-XSS-Protection "1; mode=block" always;
            add_header Referrer-Policy "strict-origin-when-cross-origin" always;
        }

        # Deny access to hidden files
        location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
        }
    }
}