Skip to content

Bug: SCIM PATCH ignores externalId on users and groups while PUT stores it #4773

Closed

Description

@yannickmonney

Bug: SCIM PATCH ignores externalId on users and groups while PUT stores it

P3. Locally reproduced at current main 4e3c8e40fe05706a5e8796bb30b024b58c1038f9 by the TALE-223 coordinator, with an independent read-only review.

Reproduction and result

Send a SCIM PATCH that sets a user's or group's externalId through the dispatchers that services/platform/backend/domains/scim/routes.ts:117-119 mounts (scimUserResourceImpl, scimGroupResourceImpl). The data layer is stubbed and records what the handler asks it to write:

Request Write the handler asks for on main Expected
PATCH /scim/v2/Users/u_1 {"op":"replace","path":"externalId","value":"ext-9"} patchUser with no externalId externalId: "ext-9"
PATCH /scim/v2/Users/u_1 path-less {"op":"replace","value":{"externalId":"ext-9"}} no externalId externalId: "ext-9"
PATCH /scim/v2/Groups/t_1 {"op":"replace","path":"externalId","value":"grp-9"} patchGroup with no externalId externalId: "grp-9"

Each request is answered 200 with the resource as it was, so the identity provider's own value never sticks. The same change sent as a full PUT is stored: replaceUser passes externalId: input.externalId (backend/core/scim/http_actions.ts:159) and replaceGroup does too (:334). The user write already accepts it on a patch: patchUser (backend/domains/scim/service.ts:597-604) upserts the link when args.externalId is set. The group patch write (patchGroup, :1042) takes no externalId at all. A provider that keeps accounts in step through PATCH therefore leaves a stale externalId on Tale's side, and every later GET returns the old value. Whether a provider then re-sends the change every cycle was not observed. A provider cannot match on externalId today anyway, because an externalId eq filter answers an empty list (#4772).

Root

  • parseUserPatch (backend/core/scim/mappers.ts:269-300) reads active, displayName, name.givenName, name.familyName, userName and emails, never externalId. Neither does parseGroupPatch (:308-347).
  • patchUserResource (backend/core/scim/http_actions.ts:168-195) and patchGroupResource (:343-369) consequently never pass it to the mutation.

The write side already expects this input. service.ts:592-594 says "an externalId-only patch does not count as a change", and service.test.ts:765-776 calls patchUser with only externalId. No HTTP request can produce that call today: PUT always sends the name and email too, and PATCH never sends externalId. The SCIM spec lists "how the different providers' request shapes are read (core/scim/)" under Not yet, so this is not a documented exclusion.

RFC 7643 §3.1 defines externalId as a common attribute the client sets; RFC 7644 §3.5.2 lets PATCH replace any writable attribute. A fix for groups also has to widen the shim's patchGroup schema (backend/domains/scim/shim.ts:113-124), which has no externalId either.

Evidence and controls

The probe below ran in an admitted, bounded check under Node vitest (server project, stubbed ctx, no database). The three cases fail. The control (a PUT of the same user with externalId) passes it to patchUser.

Probe (uncommitted test beside backend/core/scim/http_actions.ts)
import { describe, expect, it, vi } from 'vitest';
import { scimGroupResourceImpl, scimUserResourceImpl, type ScimRc } from './http_actions';

const user = { userId: 'u_1', email: '[email protected]', name: 'Ada Lovelace', active: true, externalId: 'ext-1' };
const group = { teamId: 't_1', displayName: 'Finance', memberUserIds: [], externalId: 'grp-1' };

function stubRc() {
  const runQuery = vi.fn(async (_ref: unknown, args: Record<string, unknown>) => ('userId' in args ? user : group));
  const runMutation = vi.fn(async () => null);
  const ctx = { runQuery, runMutation, runAction: vi.fn() };
  const rc = { ctx: ctx as never, organizationId: 'org_1', defaultRole: 'member' } as ScimRc;
  return { rc, runMutation };
}

const send = async (impl: typeof scimUserResourceImpl, url: string, method: string, body: unknown) => {
  const { rc, runMutation } = stubRc();
  const res = await impl(rc, new Request(url, { method, body: JSON.stringify(body), headers: { 'content-type': 'application/scim+json' } }));
  return { status: res.status, written: runMutation.mock.calls[0]?.[1] as Record<string, unknown> | undefined };
};

const patchOp = (op: unknown) => ({ schemas: ['urn:ietf:params:scim:api:messages:2.0:PatchOp'], Operations: [op] });

describe('SCIM PATCH carries externalId to the write', () => {
  it('user: path externalId', async () => {
    const r = await send(scimUserResourceImpl, 'https://tale.example/scim/v2/Users/u_1', 'PATCH',
      patchOp({ op: 'replace', path: 'externalId', value: 'ext-9' }));
    expect(r.status).toBe(200);
    expect(r.written?.externalId).toBe('ext-9');
  });

  it('user: path-less value with externalId', async () => {
    const r = await send(scimUserResourceImpl, 'https://tale.example/scim/v2/Users/u_1', 'PATCH',
      patchOp({ op: 'replace', value: { externalId: 'ext-9' } }));
    expect(r.written?.externalId).toBe('ext-9');
  });

  it('group: path externalId', async () => {
    const r = await send(scimGroupResourceImpl, 'https://tale.example/scim/v2/Groups/t_1', 'PATCH',
      patchOp({ op: 'replace', path: 'externalId', value: 'grp-9' }));
    expect(r.status).toBe(200);
    expect(r.written?.externalId).toBe('grp-9');
  });

  it('control: PUT of the user stores externalId', async () => {
    const r = await send(scimUserResourceImpl, 'https://tale.example/scim/v2/Users/u_1', 'PUT', {
      schemas: ['urn:ietf:params:scim:schemas:core:2.0:User'], userName: '[email protected]', externalId: 'ext-9', active: true,
    });
    expect(r.written?.externalId).toBe('ext-9');
  });
});

Deduplication and acceptance

All 1,385 issues were searched for externalId and SCIM PATCH. No issue reports it. #2085 [13] concerns group membership composition only.

Acceptance: a user or group PATCH that sets externalId, by path or in a path-less value, stores it as PUT does, and the response and later GETs return the new value. A PATCH without externalId leaves the stored one alone.

Limits: stubbed ctx, as in http_actions.test.ts. No identity provider or PostgreSQL was used, and the provider-side resync behaviour was not observed.

Activity

  1. added
    agent-ready
    on Oct 29, 2026
  2. added a commit that references this issue on Oct 30, 2026
    4c79b81
  3. added a commit that references this issue on Oct 30, 2026
    2c80fce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readybugservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions