CVE-2023-40027 (TypeScript, published 2023-08-15T18:15Z)
Description: value: Keystone is an open source headless CMS for Node.js — built with GraphQL and React. When `ui.isAccessAllowed` is set as `undefined`, the `adminMeta` GraphQL query is publicly accessible (no session required). This is different to the behaviour of the default AdminUI middleware, which by default will only be publicly accessible (no session required) if a `session` strategy is not defined. This vulnerability does not affect developers using the `@keystone-6/auth` package, or any users that have written their own `ui.isAccessAllowed` (that is to say, `isAccessAllowed` is not `undefined`). This vulnerability does affect users who believed that their `session` strategy will, by default, enforce that `adminMeta` is inaccessible by the public in accordance with that strategy; akin to the behaviour of the AdminUI middleware. This vulnerability has been patched in `@keystone-6/core` version `5.5.1`. Users are advised to upgrade. Users unable to upgrade may opt to write their own `isAccessAllowed` functionality to work-around this vulnerability.
Severity: nan (CVSS v3 base score: 5.3)
Weakness: CWE-862 \u2014 Missing Authorization
The product does not perform an authorization check when an actor attempts to access a resource or perform an action.
Repository: https://github.com/keystonejs/keystone
Files changed:
.changeset/fix-admin-meta-access.md
packages/core/src/admin-ui/system/generateAdminUI.ts
packages/core/src/admin-ui/system/index.ts
packages/core/src/admin-ui/templates/app.ts
packages/core/src/admin-ui/templates/index.ts
packages/core/src/fields/types/relationship/index.ts
packages/core/src/lib/admin-meta-resolver.ts
packages/core/src/lib/create-admin-meta.ts
packages/core/src/lib/createGraphQLSchema.ts
packages/core/src/lib/createSystem.ts
packages/core/src/scripts/dev.ts
Commit message: Fix `ui.isAccessAllowed` when `undefined` to prevent access (#8771)

Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com>

Vulnerable code:
import type { AdminMetaRootVal } from './createAdminMeta';
export { KeystoneMeta } from './adminMetaSchema';
import type { AdminMetaRootVal } from '../system/createAdminMeta';
import type { AdminMetaRootVal } from '../system/createAdminMeta';
import { getAdminMetaForRelationshipField } from '../../../admin-ui/system/createAdminMeta';
} from './createAdminMeta';
        if ('isAdminUIBuildProcess' in context || adminMeta.isAccessAllowed === undefined) {
        return Promise.resolve(adminMeta.isAccessAllowed(context)).then(isAllowed => {
          if (isAllowed) {
            return adminMeta;
          }
import { humanize } from '../../lib/utils';
import type { InitialisedList } from '../../lib/core/initialise-lists';
import type { FilterOrderArgs } from '../../types/config/fields';
import type { KeystoneConfig } from '../types';
import { KeystoneMeta } from '../admin-ui/system/adminMetaSchema';
import type { AdminMetaRootVal } from '../admin-ui/system/createAdminMeta';
import { createAdminMeta } from '../admin-ui/system/createAdminMeta';
import type { AdminMetaRootVal } from '../admin-ui/system/createAdminMeta';

Fixed code:
---
'@keystone-6/core': patch
---

Fixes `ui.isAccessAllowed` when `undefined`, to prevent access to the `adminMeta` GraphQL query, akin to the behaviour for the default AdminUI `pageMiddleware`
import type { AdminMetaRootVal } from '../../lib/create-admin-meta';
import type { AdminMetaRootVal } from '../../lib/create-admin-meta';
import type { AdminMetaRootVal } from '../../lib/create-admin-meta';
import { getAdminMetaForRelationshipField } from '../../../lib/create-admin-meta';
} from './create-admin-meta';
function defaultIsAccessAllowed({ session, sessionStrategy }: KeystoneContext) {
  if (!sessionStrategy) return true;
  return session !== undefined;
}

        if ('isAdminUIBuildProcess' in context) {

        const isAccessAllowed = adminMeta?.isAccessAllowed ?? defaultIsAccessAllowed;
        return Promise.resolve(isAccessAllowed(context)).then(isAllowed => {
          if (isAllowed) return adminMeta;

import type { FilterOrderArgs } from '../types/config/fields';

import { humanize } from './utils';
import type { InitialisedList } from './core/initialise-lists';
import type { KeystoneConfig } from '../types';
import { KeystoneMeta } from './admin-meta-resolver';
import type { AdminMetaRootVal } from './create-admin-meta';
import { createAdminMeta } from './create-admin-meta';
import type { AdminMetaRootVal } from '../lib/create-admin-meta';