Thabo
Thabo

Reputation: 1465

NGXS compatibility option strictContentSecurityPolicy has no effect

The Compatibility option strictContentSecurityPolicy has no effect. I am getting the following error in the browser when accessing my app because of my servers content security policy.

Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'unsafe-inline'".

NGXS: 3.8.1

@angular/core: 17.0.3

Configure the root module with these options.

NgxsModule.forRoot([], {
    developmentMode: !environment.production,
    selectorOptions: {
        suppressErrors: false,
    },
    compatibility: {
        strictContentSecurityPolicy: true,
    },
}),

To execute the compliantPropGetter instead of fastPropGetter

export function propGetter(paths: string[], config: NgxsConfig) {
  if (config?.compatibility?.strictContentSecurityPolicy) {
    return compliantPropGetter(paths);
  } else {
    return fastPropGetter(paths);
  }
}

Upvotes: 0

Views: 20

Answers (0)

Related Questions