Skip to content

Add CONCOURSE_CUSTOM_HTTP_HEADERS allowing operators to set multiple headers on all HTTP responses - #9618

Merged
taylorsilva merged 22 commits into
concourse:masterfrom
ceco556:security_headers
Jul 17, 2026
Merged

taylorsilva merged 22 commits into
concourse:masterfrom
ceco556:security_headers

Conversation

@AtanasNikov

@AtanasNikov AtanasNikov commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Changes proposed by this PR:

Adds support for configuring additional baseline security HTTP headers in Concourse by configuring CONCOURSE_ADDITIONAL_HTTP_HEADERS. When setting with the env var, each Header+Value is separated by a comma, like so: CONCOURSE_ADDITIONAL_HTTP_HEADERS: "Referrer-Policy:no-referrer,Cross-Origin-Opener-Policy:same-origin"

Unit tests are included to verify headers are set correctly and omitted when empty.

The change was validated on a dev Concourse deployment with a custom build:

  • Verified headers via curl
  • Validated browser behavior using DevTools (Network + Console)
  • Tested cross-origin scenarios (navigation, popups, resource loading)
  • Confirmed no regressions in UI/API flows

We will open PRs for concourse-bosh-release, concourse-chart and docs as well.

@Kump3r

Kump3r commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Unit test failed with unrelated errors, I am retriggering

@ceco556

ceco556 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Yes and it still failling.
There is an issue opened #9619.

@Kump3r

Kump3r commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Could you guys sync master in your fork and merge it to your feature branch, so the unit test pass? Thanks!

@taylorsilva

Copy link
Copy Markdown
Member

Should be no need rebase, we do that automatically with the PR resource. You just hit the resource cache when you re-ran it. I re-triggered it now and it's doing a fresh rebase in CI now.

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has me wondering if we need to change our approach here. I feel like instead of endlessly adding new flags for HTTP headers, we should have some way for operators to configure a set of headers that are then attached to the security handler here. This also ensures operators aren't gated on a new Concourse release when all they want to do is add a header.

I know this probably isn't how you were thinking this would go when you made this PR, but I think I'd prefer we re-evaluate how we approach these configurations flags. I'm not keen on adding the same kind of flags over and over again.

Are you open to exploring an alternative approach to this? It doesn't have to happen in this PR. We can open an issue and figure out the details in there and then create a new PR. WDYT?

@taylorsilva taylorsilva moved this from Todo to Waiting on Contributor in Pull Requests Jun 26, 2026
@Kump3r

Kump3r commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Since they are more or less set the same, what you have in mind is remove the different params and let operators provide an array/map with the headers. I think this is actually a reasonable way forward and agree if I understand it correctly. Seems simple enough to refactor, the problem would be deprecating the old properties and notifying operators of the change. Or am I missing something?

@taylorsilva

Copy link
Copy Markdown
Member

Yeah you mostly got what I'm saying. I wouldn't remove the existing flags, still use them. But yes to adding a way for operators to pass in an array of HTTP headers + values.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@ceco556

ceco556 commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

We worked together with @AtanasNikov and changed it to be an array of HTTP headers.

Tested locally and it works as expected:

docker-compose.yml:
CONCOURSE_HTTP_HEADERS: "Referrer-Policy:no-referrer,Cross-Origin-Opener-Policy:same-origin"

> curl -skI http://localhost:8080/

HTTP/1.1 200 OK
Cache-Control: no-store, private
Content-Security-Policy: frame-ancestors 'none'
Cross-Origin-Opener-Policy: same-origin
Referrer-Policy: no-referrer
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: deny
Date: Tue, 30 Jun 2026 17:31:54 GMT
Content-Length: 1413
Content-Type: text/html; charset=utf-8

@taylorsilva

taylorsilva commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

Just need @AtanasNikov to do the EasyCLA check please.

Integration test actually passed, but Github gave us a 401 back when trying to update the PR status, which triggered the on_failure hook step which DIDN'T get a 401 error. Flakey Github responses >_<
Running again, should pass.

@taylorsilva taylorsilva changed the title Add configurable baseline security HTTP headers (Referrer-Policy, COOP, CORP, COEP) Add CONCOURSE_HTTP_HEADERS allowing operators to set multiple headers on all HTTP responses Jun 30, 2026
@taylorsilva taylorsilva changed the title Add CONCOURSE_HTTP_HEADERS allowing operators to set multiple headers on all HTTP responses Add CONCOURSE_ADDITIONAL_HTTP_HEADERS allowing operators to set multiple headers on all HTTP responses Jun 30, 2026
taylorsilva
taylorsilva previously approved these changes Jun 30, 2026

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a "nit" commit on top. I preferred the flag name matching the struct field's name, so made it CONCOURSE_ADDITIONAL_HTTP_HEADERS. Also makes it clear that we set it in addition to what we also set.

I will also say that I recognize for some HTTP headers, it's common to set them to a value with commas in them value1,value2. For this case, users HAVE to use the flag version --additional-http-headers, setting it once for each header they want to add.

Otherwise this LGTM. TY for changing direction here! Once the EasyCLA is signed off we can merge this.

@IvanChalukov IvanChalukov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey folks, I really like the idea of having a property that allows adding additional HTTP headers.

That being said, I do have a concern about using a comma as the delimiter here:

CONCOURSE_ADDITIONAL_HTTP_HEADERS: "Referrer-Policy:no-referrer,Cross-Origin-Opener-Policy:same-origin"

Several HTTP headers legitimately contain comma-separated values (e.g. Cache-Control, Accept-encoding, etc.), so using “,” as a separator makes the format ambiguous and could limit which headers can be configured in the future. Would it make sense to use a less ambiguous format or delimiter?

Also, I assume this property can override predefined headers such as CSP. If that’s the case, it could be a source of confusion, so I think the documentation should be expanded to clarify the behavior and any precedence rules.

@taylorsilva

Copy link
Copy Markdown
Member

Good points Ivan. Current code does make it possible to override the "legacy" header flags (CSP,Strict-Transport-Security, and X-Frame-Options) but funnily enough, it can't override these three:

w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("X-Download-Options", "noopen")
w.Header().Set("Cache-Control", "no-store, private")

We should probably figure out the intention here. How do we expect all these flags to work together?


Another thought just occurred to me as well. Couldn't someone put a load balancer in front of their web nodes and have the load balancer add the extra headers for them?

It's nice to have Concourse have some safe defaults out of the box, but these feel like "I'm really going out of my way to really lock things down" headers that most people won't set. Is there something I'm missing though that makes it more practical to have Concourse set these headers? The original set of headers were:

  • Cross-Origin-Opener-Policy
  • Cross-Origin-Resource-Policy
  • Cross-Origin-Embedder-Policy

@AtanasNikov

Copy link
Copy Markdown
Contributor Author

Nice catch.

We are introducing a new --additional-http-headers flag that accepts a JSON object, allowing operators to configure arbitrary HTTP response headers. We chose JSON object because it correctly handles header values containing commas (for example, Cache-Control: no-cache, private), which wasn't working with go-flags' built-in delimiter parsing.

We are applying the AdditionalHTTPHeaders map after all existing header assignments in ServeHTTP, including the three currently hardcoded headers. This allows operators to override the currently default headers(X-Content-Type-Options, X-Download-Options, Cache-Control) if they explicitly choose to.
If --additional-http-headers is not specified, Concourse continues to behave exactly as it is and uses the existing default values.

Operators who want to use these or any other response headers can opt in by configuring --additional-http-headers, while everyone else continues to get the existing behavior unchanged.

@Kump3r Kump3r left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts based on the latest commits from my side.

Comment thread atc/http_headers_flag.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we introducing this as a separate module and not add it to the security_handler.go. Also there are no tests for this atm.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are introducing validatio, should we also validate that this additional headers do not have XFrameOptions, ContentSecurityPolicy, StrictTransportSecurity as those should be configured trough the dedicated properties to not have confusion?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like other such flags are validated in the command.go directly, so you should follow that pattern. Also when you change that you wouldn't need a dedicated structure and can directly let operators pass map[string]string which would then have some validations.

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this PR during the Working Group meeting today and decided on suggesting the following changes for this PR:

  • Rename flag/env var to --custom-http-headers/CONCOURSE_CUSTOM_HTTP_HEADERS and have the behaviour be to override any previously set headers. That means having it be the last one to set headers in the Security handler
  • The flag should take in a path to a JSON/YAML file that we then parse. We realized there are a lot of random characters that can go into the values of headers which makes it very difficult to parse via flags/env vars. Parsing headers from a file will be safer and easier for operators to manage.

Example of headers file:

{
  "header-1": "some; value; string;",
  "header-2": "some, value, string"
}
header-1: "some; value; string;"
header-2: "some, value, string"

@Kump3r Kump3r added this to the v8.3.0 milestone Jul 9, 2026
AtanasNikov and others added 8 commits July 13, 2026 16:55
Following the existing flag.AuthorizedKeys pattern — a new CustomHTTPHeaders type in the flag package parses and validates the file at startup via UnmarshalFlag, applying RFC 7230 validation on header names and values using `golang.org/x/net/http/httpguts`. 
Custom headers are applied last in SecurityHandler, allowing them to override any previously set header including hardcoded ones.
@AtanasNikov

Copy link
Copy Markdown
Contributor Author

We've contributed with @IvanChalukov on replacing --additional-http-headers with --custom-http-headers (CONCOURSE_CUSTOM_HTTP_HEADERS), which now accepts a path to a YAML or JSON file instead of an inline JSON string, making it safer and easier for operators to manage header values containing special characters.

Following the flag.AuthorizedKeys pattern, a new CustomHTTPHeaders type parses and validates the file at startup via UnmarshalFlag, applying RFC 7230 validation using golang.org/x/net/http/httpguts.

Custom headers are applied last in SecurityHandler, allowing them to override any previously set header.

Comment thread atc/http_headers_flag.go Resolved
Comment thread atc/atccmd/command.go Resolved
Comment thread atc/wrappa/security_handler_test.go Resolved

@IvanChalukov IvanChalukov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I've tested it locally with both YAML and JSON files:

  • JSON sample:
{
  "X-Content-Type-Options": "some; value; string;",
  "Referrer-Policy": "no-referrer",
  "Cross-Origin-Opener-Policy": "same-origin",
  "Cache-Control": "no-store",
  "dummy-header": "123asd"
}
  • YAML sample:
X-Content-Type-Options: "some; value; string;"
Referrer-Policy: "referrer"
Cross-Origin-Opener-Policy: "same-orig"
Cache-Control: "private,max-age=10"

It also fails to start web when try to set invalid header like Cache- Control: "private,max-age=10"(uses whitespaces instead of -):

error: invalid argument for flag `--custom-http-headers' 
(expected flag.CustomHTTPHeaders): invalid header name "Cache- Control" in custom HTTP headers file (/headers.yaml)

@taylorsilva taylorsilva changed the title Add CONCOURSE_ADDITIONAL_HTTP_HEADERS allowing operators to set multiple headers on all HTTP responses Add CONCOURSE_CUSTOM_HTTP_HEADERS allowing operators to set multiple headers on all HTTP responses Jul 17, 2026
@taylorsilva taylorsilva moved this from Waiting on Contributor to In Progress in Pull Requests Jul 17, 2026
@taylorsilva
taylorsilva merged commit 0c4db1e into concourse:master Jul 17, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Pull Requests Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants