Urgent.News

What's breaking now, across thousands of outlets.

Tech

nginx add_header Appends. It Doesn't Override — And That Can Remove Protection.

TL;DR — I shipped a baseline of security headers into every generated nginx vhost, meaning it as a fallback for applications that send none of their own. Within the hour, production was answering with two X-Frame-Options values: DENY from the app and SAMEORIGIN from my baseline. Browsers treat a contradictory set as no directive at all , so a header added to increase protection had removed it.…

A recent incident in the author's nginx-based system revealed an important lesson regarding the add_header directive. The developer had implemented a baseline of security headers across every generated nginx vhost to provide a fallback for applications that send no headers of their own. However, when production encountered two X-Frame-Options values - DENY from the application and SAMEORIGIN from the baseline - browsers treated it as if the header was absent, effectively removing the protection.

Initially, the author intended to prevent applications from overriding the security headers. However, they discovered that the add_header directive does not override existing headers but instead appends them. This behavior can inadvertently remove critical protections if not handled carefully. Additionally, add_header cannot query upstream headers, meaning it has no way to check if the upstream had already sent the header. Lastly, add_header replaces the entire set of headers instead of merging them.

The author learned that to resolve this issue, they needed to map upstream headers using the $upstream_http_* variables and add_header statements, allowing the baseline headers to be inherited only when the upstream had not set the corresponding header. This change ensured that applications maintaining their own security headers would not have their protections weakened by the baseline.

The fix involved creating maps for the X-Content-Type-Options, X-Frame-Options, and Referrer-Policy headers, allowing the system to utilize the upstream values when available and fall back to the baseline when necessary.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

The board came back. The highlights lied.

I ship Codenames AI , a web game. Each game mode keeps its own save in localStorage . Reload the tab, switch to a different mode, come back later: the board, turn, clue history, and in-progress…

  • Codenames AI retains game data upon reload.
  • Per-mode persistence of clicks resolves highlighting confusion.
  • AI-generated clues shouldn't persist across reloads.

Guide to DNS on Ubuntu 26.04

For years my understanding of DNS on a Linux box was one file. /etc/resolv.conf has a nameserver line, that is where lookups go, done.

More from Friday 4 September →