Access callbacks allow only on a literal true (owner's decision for 1.18.0), strictAccessAnswers: false for the old reading; the new 1.18.0 security options checked strictly at start; docs, skills, changelog

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 17:07:04 +01:00
co-authored by Claude Opus 5.5
parent d90825a396
commit c6bfb621f5
25 changed files with 1450 additions and 62 deletions
+43 -15
View File
@@ -1,12 +1,12 @@
/**
* Access callbacks of a project (`cookieScanner.access`, the doctor's `access`), owner's decision Q4, 1.18.0:
* still allowed on any truthy answer, but an answer that is not a boolean is reported once per option, so a
* project sees it before the next minor version allows only `true`. Every call site goes through one function.
* Access callbacks of a project (`cookieScanner.access`, the doctor's `access`), owner's decision for 1.18.0: only a
* literal `true` allows; an answer that is not a boolean is reported once per option; `strictAccessAnswers: false`
* gives the old truthy reading back. Every call site goes through one function.
*/
import { readFileSync } from 'node:fs'
import { beforeEach, describe, expect, test, vi } from 'vitest'
import { accessAllowed, resetAccessWarnings } from '../src/modules/shared/accessAnswer.js'
import { accessAllowed, resetAccessWarnings, strictAccessAnswers } from '../src/modules/shared/accessAnswer.js'
beforeEach(() => resetAccessWarnings())
@@ -18,19 +18,47 @@ describe('accessAllowed', () => {
expect(warn).not.toHaveBeenCalled()
})
test.each([
[{ id: 1 }, true, 'an object'],
['no', true, 'a string'],
[1, true, 'a number'],
[null, false, 'null'],
[undefined, false, 'a undefined'],
])('%j is read as before (%s) and reported once', (answer, allowed, kind) => {
// the owner's decision for 1.18.0: only a literal `true` allows (the old reading in the third column)
const answers: [string, unknown, boolean, string][] = [
['an object (req.user)', { id: 1 }, true, 'an object'],
['1', 1, true, 'a number'],
['a string', 'yes', true, 'a string'],
['null', null, false, 'null'],
['undefined', undefined, false, 'an undefined'],
]
test.each(answers)('%s refuses (strict, the default) and is reported once, naming the option and the fix', (_, answer, _old, kind) => {
const warn = vi.fn()
expect(accessAllowed('doctor.access', answer, { warn })).toBe(allowed)
expect(accessAllowed('doctor.access', answer, { warn })).toBe(allowed)
expect(accessAllowed('doctor.access', answer, { warn })).toBe(false)
expect(accessAllowed('doctor.access', answer, { warn })).toBe(false)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls[0][0]).toContain(`doctor.access returned ${kind}`)
expect(warn.mock.calls[0][0]).toContain('only `true` allows')
expect(warn.mock.calls[0][0]).toContain('Boolean(req.user)')
})
test.each(answers)('%s with strictAccessAnswers: false is read as before 1.18.0 (truthy allows)', (_, answer, old) => {
expect(accessAllowed('cookieScanner.access', answer, { strict: false, warn: vi.fn() })).toBe(old)
})
test('a Promise is never `true`: an un-awaited answer refuses, whatever it holds', () => {
const warn = vi.fn()
for (const value of [true, { id: 1 }, 1, 'yes']) {
const p = Promise.resolve(value)
expect(accessAllowed('doctor.access', p, { warn })).toBe(false)
}
expect(warn.mock.calls[0][0]).toContain('a Promise (not awaited)')
})
test('async callbacks: the call sites await the answer, so a Promise of each reads like the value itself', async () => {
const asCalled = async (cb: () => Promise<unknown>) => accessAllowed('cookieScanner.access', await cb(), { warn: vi.fn() })
expect(await asCalled(async () => true)).toBe(true)
for (const value of [{ id: 1 }, 1, 'yes', false, null]) {expect(await asCalled(async () => value)).toBe(false)}
})
test('strictAccessAnswers(req) reads the option from the request\'s config', () => {
expect(strictAccessAnswers(undefined)).toBe(true)
expect(strictAccessAnswers({ payload: { config: { custom: {} } } })).toBe(true)
expect(strictAccessAnswers({ payload: { config: { custom: { iapl: { strictAccessAnswers: false } } } } })).toBe(false)
})
test('each option is reported on its own', () => {
@@ -47,6 +75,6 @@ test('every call of a project access callback goes through accessAllowed', () =>
const text = readFileSync(file, 'utf8')
const calls = text.match(/await options\.access\(\{ req \}\)/g) ?? []
expect(calls.length, file).toBeGreaterThan(0)
expect(text.match(/accessAllowed\('[\w.]+', await options\.access\(\{ req \}\)\)/g)?.length, file).toBe(calls.length)
expect(text.match(/accessAllowed\('[\w.]+', await options\.access\(\{ req \}\), \{ strict: strictAccessAnswers\(req\) \}\)/g)?.length, file).toBe(calls.length)
}
})
+8
View File
@@ -130,6 +130,14 @@ describe('switches refuse nonsense at start', () => {
['mail.relay', { mail: { relay: 'off' } }],
['storageNames', { storageNames: 'IAPL' }],
['forms.attachments.submit.maxPerMinute', { forms: { attachments: { submit: { maxPerMinute: 'off' } } } }],
// 1.18.0, security audit fixes: none of these may read as "off"
['listLimit', { listLimit: 0 }],
['listLimit', { listLimit: 'false' }],
['listLimit.max', { listLimit: { max: 0 } }],
['listLimit.exclude', { listLimit: { exclude: 'products' } }],
['refuseOperatorSort', { refuseOperatorSort: 'false' }],
['lockedDocuments', { lockedDocuments: 0 }],
['strictAccessAnswers', { strictAccessAnswers: 'false' }],
])('%s: %j fails at start', async (name, options) => {
expect(await start(options)).toThrow(name)
})