Skip to content

Set security relevant response headers for ng serve #15729

@jofrly

Description

@jofrly

🚀 Feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [x] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Description

I want to set a response header for every request served by ng serve (e.g. Content-Security-Policy to make my local development environment more equal to the production environment.

Describe the solution you'd like

An option might be to be able to set headers within the angular.json's serve section

Describe alternatives you've considered

I tried to add a wildcard entry in the proxy.conf.js file (/**) and set the header within the onProxyRes method like so:

    onProxyRes: (proxyRes, req, res) => {
      proxyRes.headers['Content-Security-Policy'] = 'default-src \'self\' \'unsafe-eval\' \'unsafe-inline\'';
    }

But this method does not get triggered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions