Skip to content
Myr

fix(secure-headers): output standard empty parentheses () instead of none for disabled Permissions-Policy directives (#5197)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nanasi · committed by GitHub · parent cf78528 · Browse files · 2 files+7 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+7 added−4 removed

  • tests:+1 added−1 removed
  • other:+6 added−3 removed

2 files+7 added−4 removed

modified:src/middleware/secure-headers/index.test.ts+1 added-1 removed
185 unmodified lines
186 )187188 const res = await app.request('/test')189 expect(res.headers.get('Permissions-Policy')).toEqual(190 'fullscreen=(self), bluetooth=none, payment=(self "example.com"), sync-xhr=(), camera=none, microphone=*, ' +190 'fullscreen=(self), bluetooth=(), payment=(self "example.com"), sync-xhr=(), camera=(), microphone=*, ' +191 'geolocation=*, usb=(self "https://a.example.com" "https://b.example.com"), ' +192 'accelerometer=("https://*.example.com"), gyroscope=(src), ' +193 'magnetometer=("https://a.example.com" "https://b.example.com")'194 )
474 unmodified lines
modified:src/middleware/secure-headers/secure-headers.ts+6 added-3 removed
295 unmodified lines
296 .map(([directive, value]) => {297 const kebabDirective = camelToKebab(directive)298299 if (typeof value === 'boolean') {300 return `${kebabDirective}=${value ? '*' : 'none'}`300 return `${kebabDirective}=${value ? '*' : '()'}`301 }302303 if (Array.isArray(value)) {304 if (value.length === 0) {305 return `${kebabDirective}=()`306 }307 if (value.length === 1 && (value[0] === '*' || value[0] === 'none')) {308 return `${kebabDirective}=${value[0]}`307 if (value.length === 1 && value[0] === '*') {308 return `${kebabDirective}=*`309 }310 if (value.length === 1 && value[0] === 'none') {311 return `${kebabDirective}=()`312 }313 const allowlist = value.map((item) => (['self', 'src'].includes(item) ? item : `"${item}"`))314 return `${kebabDirective}=(${allowlist.join(' ')})`315 }316
25 unmodified lines