Content Security Policy (CSP.md)
Defining your policy
src/environments/csp/csp.dev.ts
src/environments/csp/csp.dev.ts// types imported from the 'csp-header' package, which is included in Valtimo FE libs 11.2.0 and up
import {CSPHeaderParams, DATA, SELF, UNSAFE_EVAL, UNSAFE_INLINE} from 'csp-header';
// optional import of utilities to manipulate URL strings
import {UrlUtils} from '@valtimo/config';
// the Keycloak configuration used on the development environment
import {authenticationKeycloak} from '../auth/keycloak-config.dev';
// in this object we define our CSP headers, which must conform to the type CSPHeaderParams (imported from 'csp-header')
export const cspHeaderParamsDev: CSPHeaderParams = {
directives: {
'default-src': [SELF],
// DATA is needed because of use of inline images
'img-src': [SELF, DATA],
/*
UNSAFE_EVAL is needed because of javascript in form.io forms (i.e. on summary page)
Scripts loaded from https://cdn.form.io/ are allowed, otherwise Form.IO won't work in our app.
*/
'script-src': [SELF, UNSAFE_EVAL, UNSAFE_INLINE, 'https://cdn.form.io/'],
/*
DATA is needed because of use of inline fonts.
Some external sources are allowed which are used in the Valtimo front-end libraries.
*/
'font-src': [
SELF,
DATA,
UNSAFE_INLINE,
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/',
'https://fonts.gstatic.com',
],
'connect-src': [
SELF,
// connect-src must contain the root url of the keycloak instance the application uses to login
UrlUtils.getUrlHost(authenticationKeycloak.options.keycloakOptions.config.url),
],
'style-src': [
SELF,
// UNSAFE_INLINE is needed because of use of inline styles
UNSAFE_INLINE,
// external styles sources used by the Valtimo FE libs
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/',
'https://fonts.googleapis.com',
],
},
};Including your policy
src/environments/environment.ts
src/environments/environment.tsExtending your policy
Last updated