Skip to content

Set Content-Security-Policy and Cache-Control Headers - #6949

Merged
taylorsilva merged 5 commits into
masterfrom
sec-headers
May 4, 2021
Merged

taylorsilva merged 5 commits into
masterfrom
sec-headers

Conversation

@taylorsilva

@taylorsilva taylorsilva commented Apr 28, 2021 •

Copy link
Copy Markdown
Member

What does this PR accomplish?

Bug Fix | Feature | Documentation

Changes proposed by this PR:

  • Add CSP headers that are configurable. Defaults to frame-ancestors 'none'
  • Add a default cache-control header set to no-store, private

Notes to reviewer:

I'm not 100% sure about the cache-control values, but looking at the
header of some big sites (i.e. stackoverflow) I found they do set this header
to private.

Release Note

  • A Content-Security-Policy header is now set with a default value that will block framing of the Concourse web UI. This was already possible with the default value of the X-Frames-Option header.
    • The CSP header value is configurable with CONCOURSE_CONTENT_SECURITY_POLICY
  • A Cache-Control header is set on every page with a default value of no-store, private. The value of the header is overwritten for some paths (i.e. web assets)

Contributor Checklist

Reviewer Checklist

  • Code reviewed
  • Tests reviewed
  • Documentation reviewed
  • Release notes reviewed
  • PR acceptance performed
  • New config flags added? Ensure that they are added to the
    BOSH and
    Helm packaging; otherwise, ignored for
    the integration
    tests

    (for example, if they are Garden configs that are not displayed in the
    --help text).

defaults to `frame-ancestors 'none'` to block framing. Users can
configure the header to have a more robust CSP to meet their security
needs.

Docs: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors

Signed-off-by: Taylor Silva <[email protected]>
I'm not 100% sure this is the best thing to do, but looking at the
header of some big sites (i.e. stackoverflow) I found they do set this header
to `private`.

Signed-off-by: Taylor Silva <[email protected]>

@aoldershaw aoldershaw 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.

@EstebanFS and I tried to better understand what these headers do. It sounds like the frame-ancestors in Content-Security-Policy obsoletes X-Frame-Options, which we also allow configuring - however, it isn't supported in IE, so probably makes sense to support both.

For Cache-Control, I guess these settings just mean don't cache anything. This makes sense for things that should be private/sensitive (like API responses), but probably isn't the best for things like assets (icons, stylesheets, javascript).

Also interesting that we explicitly set Cache-Control to cache these assets: https://github.com/concourse/concourse/blob/master/web/cache_handler.go. It seems like both values are sent back in the response - not sure which takes precedence

Screen Shot 2021-04-29 at 5 30 16 PM

I feel like a default value for Cache-Control of private might be a bit better, but not sure if that'll satisfy the vulnerability scanner.

@analytically

Copy link
Copy Markdown
Contributor

I'll be adding support for HSTS (https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security) in a separate PR once this one is merged.

@taylorsilva

taylorsilva commented Apr 30, 2021 •

Copy link
Copy Markdown
Member Author

Interesting about both Cache-Control headers being returned. I thought later handlers would overwrite it. Not sure how browsers are meant to handle conflicting headers like that either. (EDIT: didn't find this explicitly anywhere but I'm guessing the strictest rule is what gets enforced when there's conflicting rules).

Also thought about setting it to private instead of private, no-store. Didn't for the reason you gave, not sure if it will satisfy the vulnerability scanner :(

@aoldershaw

Copy link
Copy Markdown
Contributor

I thought later handlers would overwrite it

I think we can get it to overwrite by using w.Header.Set rather than w.Handler.Add (in web/cache_handler):

w.Header().Add("Cache-Control", fmt.Sprintf("max-age=%d, private", yearInSeconds))

@taylorsilva

Copy link
Copy Markdown
Member Author

I changed Cache-Control to only have private. Also changed the cache_handler to overwrite any previous cache-control headers as per your comment. I checked git blame history on that line but didn't see any reason why it had to be Add instead of Set, and I can't think of any myself. Didn't break any unit tests either.

Comment thread atc/wrappa/security_handler.go Resolved

@aoldershaw aoldershaw 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.

@taylorsilva
taylorsilva merged commit efee34e into master May 4, 2021
@taylorsilva
taylorsilva deleted the sec-headers branch May 4, 2021 15:23
@taylorsilva

Copy link
Copy Markdown
Member Author

I'm gonna go make the packaging PR's for this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

misc release/undocumented This didn't warrant being documented or put in release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants