mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
task: added flag to remove unsafe inline style src header (#7566)
Our CSP reports that unsafe-inline is not recommended for styleSrc. This PR adds a flag for making it possible to remove this element of our CSP headers. It should allow us to see what (if anything) breaks hard.
This commit is contained in:
parent
3fe110f155
commit
8bee33fa48
@ -145,6 +145,7 @@ exports[`should create default config 1`] = `
|
|||||||
"personalAccessTokensKillSwitch": false,
|
"personalAccessTokensKillSwitch": false,
|
||||||
"projectOverviewRefactorFeedback": false,
|
"projectOverviewRefactorFeedback": false,
|
||||||
"queryMissingTokens": false,
|
"queryMissingTokens": false,
|
||||||
|
"removeUnsafeInlineStyleSrc": false,
|
||||||
"resourceLimits": false,
|
"resourceLimits": false,
|
||||||
"responseTimeMetricsFix": false,
|
"responseTimeMetricsFix": false,
|
||||||
"responseTimeWithAppNameKillSwitch": false,
|
"responseTimeWithAppNameKillSwitch": false,
|
||||||
|
@ -5,6 +5,20 @@ import { hoursToSeconds } from 'date-fns';
|
|||||||
|
|
||||||
const secureHeaders: (config: IUnleashConfig) => RequestHandler = (config) => {
|
const secureHeaders: (config: IUnleashConfig) => RequestHandler = (config) => {
|
||||||
if (config.secureHeaders) {
|
if (config.secureHeaders) {
|
||||||
|
const includeUnsafeInline = !config.flagResolver.isEnabled(
|
||||||
|
'removeUnsafeInlineStyleSrc',
|
||||||
|
);
|
||||||
|
const styleSrc = ["'self'"];
|
||||||
|
if (includeUnsafeInline) {
|
||||||
|
styleSrc.push("'unsafe-inline'");
|
||||||
|
}
|
||||||
|
styleSrc.push(
|
||||||
|
'cdn.getunleash.io',
|
||||||
|
'fonts.googleapis.com',
|
||||||
|
'fonts.gstatic.com',
|
||||||
|
'data:',
|
||||||
|
...config.additionalCspAllowedDomains.styleSrc,
|
||||||
|
);
|
||||||
const defaultHelmet = helmet({
|
const defaultHelmet = helmet({
|
||||||
hsts: {
|
hsts: {
|
||||||
maxAge: hoursToSeconds(24 * 365 * 2), // 2 non-leap years
|
maxAge: hoursToSeconds(24 * 365 * 2), // 2 non-leap years
|
||||||
@ -26,15 +40,7 @@ const secureHeaders: (config: IUnleashConfig) => RequestHandler = (config) => {
|
|||||||
'fonts.gstatic.com',
|
'fonts.gstatic.com',
|
||||||
...config.additionalCspAllowedDomains.fontSrc,
|
...config.additionalCspAllowedDomains.fontSrc,
|
||||||
],
|
],
|
||||||
styleSrc: [
|
styleSrc,
|
||||||
"'self'",
|
|
||||||
"'unsafe-inline'",
|
|
||||||
'cdn.getunleash.io',
|
|
||||||
'fonts.googleapis.com',
|
|
||||||
'fonts.gstatic.com',
|
|
||||||
'data:',
|
|
||||||
...config.additionalCspAllowedDomains.styleSrc,
|
|
||||||
],
|
|
||||||
scriptSrc: [
|
scriptSrc: [
|
||||||
"'self'",
|
"'self'",
|
||||||
'cdn.getunleash.io',
|
'cdn.getunleash.io',
|
||||||
|
@ -65,7 +65,8 @@ export type IFlagKey =
|
|||||||
| 'resourceLimits'
|
| 'resourceLimits'
|
||||||
| 'extendedMetrics'
|
| 'extendedMetrics'
|
||||||
| 'cleanApiTokenWhenOrphaned'
|
| 'cleanApiTokenWhenOrphaned'
|
||||||
| 'allowOrphanedWildcardTokens';
|
| 'allowOrphanedWildcardTokens'
|
||||||
|
| 'removeUnsafeInlineStyleSrc';
|
||||||
|
|
||||||
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
|
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
|
||||||
|
|
||||||
@ -314,6 +315,10 @@ const flags: IFlags = {
|
|||||||
process.env.UNLEASH_EXPERIMENTAL_CLEAN_API_TOKEN_WHEN_ORPHANED,
|
process.env.UNLEASH_EXPERIMENTAL_CLEAN_API_TOKEN_WHEN_ORPHANED,
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
|
removeUnsafeInlineStyleSrc: parseEnvVarBoolean(
|
||||||
|
process.env.UNLEASH_EXPERIMENTAL_REMOVE_UNSAFE_INLINE_STYLE_SRC,
|
||||||
|
false,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const defaultExperimentalOptions: IExperimentalOptions = {
|
export const defaultExperimentalOptions: IExperimentalOptions = {
|
||||||
|
Loading…
Reference in New Issue
Block a user