Skip to content

fix: check the ids that the other delete functions put into a request path - #1218

Merged
vscheuber merged 15 commits into
mainfrom
fix/library-delete-functions-check-ids-2
Nov 30, 2026
Merged

vscheuber merged 15 commits into
mainfrom
fix/library-delete-functions-check-ids-2

Conversation

@vscheuber

@vscheuber vscheuber commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Second half of the delete functions that check the id they put into the path of a request (the first half, #1217, did IDM configuration entities, connectors, mappings, email templates and services). A delete* function that is given an id that is not one name (empty, . or .., a slash, a backslash, ?, #, %, a control character, a lone surrogate, a blank at either end, a leading ;) refuses it before it sends any request, a read included, and throws a FrodoError whose message says what an id has to be and does not hold the id. A function that deletes what a list holds, or an object that it finds by a name, checks each id that the tenant lists as one item: a refused id is one failed item, like an item whose delete fails with HTTP 500, and the other items are tried or not exactly as they are for that failure. The rule is the one that a push already applies to the ids of a file set: https://github.com/rockcarver/frodo-lib/blob/main/decisions/0021-crudq-naming-for-facade-methods-and-pull-and-push-as-file-set-verbs.md (a safe segment is one name that no request layer or server reads as more).

With this change every function of the frodo facade whose name starts with delete is accounted for by a test: a row for the ids that a caller gives, a scenario for the ids that a tenant lists, or a reason why it has no id in the path of a request. The list of functions that were not covered yet is empty, and a function that is added without one of the three fails the walk.

Part of #1192 (its delete half; the reads and writes of services that also put an id into a path are a follow-up)
Part of rockcarver/frodo-cli#1264

What each family checks

  • Agents (deleteAgents, deleteAgent, and the four of each of the identity gateway, Java, web and AI agents): the id that the tenant lists, once, in the one function that every agent delete goes through; deleteAIAgents checks the id before it looks the agent up.
  • Journeys and nodes: deleteJourney (a refused id comes back in the status, error, and nothing is requested or shown; a node of the deleted journey with such an id is a failed node, and a container node with such an id is not read), deleteJourneys (it reports in the status of each journey and never throws, as before), deleteNode (node id, type, version of the type), deleteCustomNode (the id that is sent, which is the one given and -1; and the id that the tenant lists for a display name), deleteCustomNodes.
  • Scripts: deleteScript, deleteScriptByName (it looks the script up by name and deletes it by the id that the tenant lists, which is now checked in between; two requests, as before), deleteScripts.
  • Cloud environment: deleteSecret and deleteVersionOfSecret on the facade (which call the api layer, so they check inline), the ops deleteSecret, pruneVersionsOfSecret (the secret id first, each listed version), deleteVariable, deleteCertificate(s) (deleteCertificates with force does not deactivate a certificate with such an id either: nothing is sent for it), deleteCSR(s), deleteLogApiKey(s), deleteTelemetry (each listed exporter), deleteSigningKeyPairById, deleteSigningKeyPairCertificate, deleteIdpAdapterById, deleteAdminFederationProvider.
  • IGA: certification templates, events, glossary schemas, request forms, request types and workflows (one, by name, all), deleteWorkflow refuses once before the draft and the published workflow; deleteOrphanedRequestFormAssignments refuses a workflow id that is not one name (it goes into the path of two reads). The other ids that it takes select which assignments are looked at, and the assignments are removed with the body of a POST built from what the tenant lists, so no id goes into the path of the removal; the filters of the reads are out of scope.
  • Secret stores and mappings: type, id (not for the type EnvironmentAndSystemPropertySecretStore, whose request names the type and ends there), mapping id; the adapter of the AI agent feature that calls the api layer checks its own ids.
  • AM and IDM objects: OAuth2 clients, trusted issuers, policies, policy sets, resource types (by id and by name), realms (by id and by name), circles of trust, social identity providers, SAML2 providers (the id that the tenant lists for the provider; the entity id is a URL and is not checked), applications (deleteApplication before the glossary of an IGA application is deleted, deleteApplicationOwnedObjectsById; the objects that an application owns go through the delete function of their own type, so a refused one is reported as failed), managed objects (type and id), managed system objects (type and id), system objects (system, type, id), internal roles.
  • importService and importServices with the option that cleans first delete through deleteFullService, so a service id that is not one name (or, for a global service, federation/<name>) is refused before any request (it is in MIGRATION.md).

Exempt, with the reason (each is in the walk with it): frodo.theme.deleteTheme, deleteThemeByName, deleteThemes (the whole ui/themerealm entity is read and rewritten, no id goes into a path); frodo.idm.staticUserMapping.deleteStaticUserMapping (changed in memory); frodo.oauth2oidc.provider.deleteOAuth2Provider (no id); frodo.idm.remoteProxy.deleteRemoteProxy and deleteRemoteProxies (a stricter name check of their own); frodo.oauth2oidc.cimd.deleteCIMDProfile and deleteCIMDProfiles (a check of their own, and the api layer encodes the id); the four functions that touch no request (deleteConnectionProfile, deleteConnectionProfileAlias, deleteHost, deleteDeepByKey).

What each commit does

  1. feat: add the check of the id of a secret store: assertSecretStoreId in the internal helper module, with its unit test.
  2. fix: refuse an id that is not one name in the remaining delete functions: the checks, as the first statement of each function (before the first read), and the tests: the rows of the facade walk (an id that the caller gives: each hostile value; nothing is requested and no message holds the id), and the scenarios of DeleteFunctions.bulkItems.unit.test.ts, which run each list function twice against a fake tenant, once with a refused id and once with an item whose delete fails with HTTP 500, and compare what was deleted, whether the call was rejected and how many failures it reports.
  3. docs: extend the MIGRATION.md entry of the checked delete ids to every delete function.
  4. test: cover the checks that the first runs of the mutants showed untested and test: name the rule of a row of the walk by what it is.
  5. The merge of origin/main.

After the first review and QA:

  1. test: fix the types of the tests of the delete functions: tsc over the test files refused six places of the walk (a catch that gave a union, a print handler); nothing is asserted differently.
  2. docs: say that deleteJourneys never throws in MIGRATION.md: deleteJourneys was listed with the functions that throw one error after the last item. It resolves with the status of every journey; a refused or failed journey has status: 'error' and an error, and a result callback gets no error argument.
  3. fix: send no request for a listed id that is not one name, deactivation and reads included: deleteCertificates with force sent a PATCH to deactivate an active certificate that the tenant lists with such an id before its delete refused it (the certificate is skipped by the deactivation now); deleteJourney read a container node by such an id (it is a failed node that is not read); deleteAIAgents sent the listed id in the filter of a read (it is refused before the agent is looked up). Each has a test that sends nothing for the refused id while the ids around it are handled as before.
  4. test: cover the calls that leave an optional argument out, the id of a custom node and a script that is not found: deleteSecretStore, deleteSecretStoreMapping and deleteSecretStoreMappings without a type; deleteCustomNode checks and sends the id with the -1 that it adds; deleteScriptByName for a name that no script has.
  5. fix: check the workflow id of deleteOrphanedRequestFormAssignments: the workflow id goes into the path of two reads; no id goes into the path of the removal (a POST built from what the tenant lists), and the filters that the other ids go into are out of scope. The function has a row now and is no longer exempt.
  6. fix: check the type of deleteManagedObjects, deleteManagedSystemObject and deleteManagedSystemObjects: the type was sent in the query of the read before any check.
  7. docs: correct the wording of the @throws sentences of the checked delete functions and of a comment.
  8. The merge of origin/main (the release commit of 5.0.0-61).
  9. test: cover a mix of active and inactive certificates, the verbose text of a refused container node and an empty workflow id: three tests added to the walk, no change to the code. deleteCertificates with force on a list of active, inactive and refused certificates deactivates only the active ones with a good id, deletes every good one and sends nothing for a refused one; the verbose text of a refused container node holds no id; an empty workflow id of deleteOrphanedRequestFormAssignments is none (it is not refused and sends what a call without a workflow id sends).

Decisions taken

  • The check is in the ops layer, the first statement, before any read or any progress output; the api layer is unchanged. Where an ops function calls the api layer directly (the facade methods deleteSecret and deleteVersionOfSecret, the delete of a version in pruneVersionsOfSecret, the adapter of the AI agent feature), the check is made there. Reversible: yes.
  • No new FrodoError code and no new public name; assertSecretStoreId is internal. The existing messages that name an id stay as they are; the refusal never holds one.
  • The functions that stopped at the first failed item for a request that failed still do (deleteTelemetry, deleteManagedObjects and deleteManagedSystemObjects within a page, and the ones that call getResult without a result callback); MIGRATION.md lists which.
  • deleteManagedObjects, deleteManagedSystemObject and deleteManagedSystemObjects check the type too, as the first statement (the real values, alpha_user, svcacct and teammember, are each one name). The existing mocked test ManagedSystemObjectOps.errorWrapping.unit.test.ts passed a type with slashes (system/ldap/account), which is not a type of these functions; it now passes teammember.
  • deleteCustomNode adds -1 to an id that does not end in it, so an id that is only refused for its end (a blank, a dot) becomes a name; the id that is sent is the one that is checked.
  • Not changed: the reads and writes of services, remove* functions, the api layer, the MCP metadata and policies.

The recorded answers, before any check was added

Every list that the recordings of this repository and the end-to-end recordings of frodo-cli (test/e2e/mocks at commit 6e5bcb0c5, read only) hold for a family of this change was checked against the rule; no id of any family is refused. Every DELETE request that the two sets record (252 in this repository, 317 in the CLI recordings) was checked too: the only segment that the rule would refuse is the empty id of the secret store of the type that has one store and no id (1 and 2 requests), which is not checked. Rows of a family with no recorded answer in a repository say so.

family library: answers / ids / distinct / refused CLI mocks: answers / ids / distinct / refused
agents 236 / 1311 / 71 / 0 265 / 934 / 40 / 0
journeys 29 / 528 / 71 / 0 127 / 2483 / 62 / 0
nodes 29 / 497 / 170 / 0 76 / 469 / 137 / 0
node types (the nodeType of a node) 2 / 410 / 239 / 0 1 / 196 / 196 / 0
scripts 29 / 1348 / 144 / 0 104 / 5548 / 219 / 0
cloud: secrets 10 / 74 / 30 / 0 50 / 333 / 31 / 0
cloud: secret versions 5 / 31 / 7 / 0 37 / 120 / 21 / 0
cloud: variables 12 / 89 / 33 / 0 42 / 572 / 19 / 0
cloud: certificates 6 / 28 / 25 / 0 no recorded answer
cloud: CSRs 3 / 49 / 44 / 0 no recorded answer
cloud: log API keys no recorded answer no recorded answer
cloud: telemetry exporters 21 / 21 / 5 / 0 19 / 19 / 2 / 0
IGA: certification templates 10 / 28 / 9 / 0 no recorded answer
IGA: events 51 / 163 / 12 / 0 no recorded answer
IGA: glossary schemas 3 / 3 / 2 / 0 no recorded answer
IGA: request forms 1 / 1 / 1 / 0 no recorded answer
IGA: request types 26 / 43 / 29 / 0 2 / 2 / 1 / 0
IGA: workflows 8 / 353 / 43 / 0 no recorded answer
secret stores 28 / 122 / 8 / 0 35 / 182 / 5 / 0
secret store mappings 20 / 189 / 44 / 0 44 / 601 / 44 / 0
OAuth2 clients 18 / 66 / 29 / 0 52 / 494 / 36 / 0
trusted JWT issuers 13 / 49 / 18 / 0 19 / 31 / 5 / 0
policies 27 / 976 / 217 / 0 68 / 2965 / 189 / 0
policy sets 30 / 135 / 25 / 0 78 / 372 / 18 / 0
resource types 35 / 149 / 20 / 0 88 / 318 / 14 / 0
realms 25 / 80 / 19 / 0 115 / 332 / 5 / 0
circles of trust 24 / 66 / 8 / 0 49 / 123 / 6 / 0
social identity providers and admin federation providers 33 / 212 / 29 / 0 116 / 790 / 30 / 0
SAML2 providers (the stub _id, base64) 50 / 149 / 21 / 0 121 / 456 / 21 / 0
applications (managed objects) 8 / 37 / 25 / 0 41 / 90 / 19 / 0
managed objects 13 / 61 / 39 / 0 59 / 146 / 34 / 0
system objects 12 / 1011 / 1004 / 0 no recorded answer
internal roles 8 / 57 / 9 / 0 33 / 206 / 9 / 0

Families with no recorded list at all: the log API keys. Reproduce with the script below (node 22 or later; read only): node sweep.mjs src/test/mock-recordings in a checkout of this repository, and for the CLI recordings git -C <frodo-cli> archive 6e5bcb0c5 test/e2e/mocks | tar -x -C <dir> and node sweep.mjs <dir>.

sweep.mjs
// Sweep of the recorded LIST answers per family of delete functions (read only).
// Usage: node sweep.mjs <dir with .har files> [<dir> ...]
// For every family: the lists that the family's list/bulk functions delete from, the field that holds the id that goes into the path, and
// the rule of the check of the family (isRequestSegment: a verbatim port of src/utils/RequestPathUtils.ts). A family line shows how many
// recorded answers were found, how many ids, how many distinct ids and which distinct ids the rule refuses.
import fs from 'node:fs';
import path from 'node:path';

function isRequestSegment(value) {
  return (
    typeof value === 'string' &&
    value !== '' &&
    value !== '.' &&
    value !== '..' &&
    !/^\.{0,2}\p{Z}*;/u.test(value) &&
    !/[/\\?#%\p{Cc}]/u.test(value) &&
    !/^\p{Z}|\p{Z}$/u.test(value) &&
    value.isWellFormed()
  );
}

const REALM = '(?:/realms/root(?:/realms/[^/]+)*)?';
const RC = `/am/json${REALM}/realm-config`;
const GC = '/am/json/global-config';

/** each family: name, the functions, and the list endpoints (method, regex of the path, query test, id fields) */
const FAMILIES = [
  {
    name: 'agents',
    functions: 'deleteAgents, deleteIdentityGatewayAgents, deleteJavaAgents, deleteWebAgents, deleteAIAgents (listed `_id`)',
    lists: [
      { method: 'POST', path: new RegExp(`^${RC}/agents$`), action: /^(nextdescendents|getAllTypes)$/ },
      { method: 'POST', path: new RegExp(`^${GC}/agents$`), action: /^(nextdescendents|getAllTypes)$/ },
      { method: 'GET', path: new RegExp(`^${RC}/agents/(J2EEAgent|WebAgent|IdentityGatewayAgent|AIAgent|SharedAgent|SoapSTSAgent|RemoteConsentAgent|2\\.2_Agent)$`) },
    ],
    fields: ['_id'],
  },
  {
    name: 'journeys',
    functions: 'deleteJourney, deleteJourneys (listed `_id` of the trees)',
    lists: [{ method: 'GET', path: new RegExp(`^${RC}/authentication/authenticationtrees/trees$`) }],
    fields: ['_id'],
  },
  {
    name: 'nodes',
    functions: 'deleteNode (the ids of the nodes of a deleted journey, `nodeType`), deleteCustomNode, deleteCustomNodes (listed `_id`)',
    lists: [
      { method: 'POST', path: new RegExp(`^${RC}/authentication/authenticationtrees/nodes$`), action: /^(nextdescendents)$/ },
      { method: 'GET', path: new RegExp(`^${RC}/authentication/authenticationtrees/nodes/[A-Za-z0-9._-]+(/[0-9.]+)?$`) },
      { method: 'GET', path: /^\/am\/json\/node-designer\/node-type$/ },
    ],
    fields: ['_id'],
  },
  {
    name: 'node types (the `nodeType` of a node)',
    functions: 'deleteNode',
    lists: [{ method: 'POST', path: new RegExp(`^${RC}/authentication/authenticationtrees/nodes$`), action: /^(getAllTypes)$/ }],
    fields: ['_id'],
  },
  {
    name: 'scripts',
    functions: 'deleteScript, deleteScriptByName, deleteScripts (listed `_id`)',
    lists: [{ method: 'GET', path: new RegExp(`^/am/json${REALM}/scripts$`) }],
    fields: ['_id'],
  },
  {
    name: 'cloud: secrets',
    functions: 'deleteSecret, pruneVersionsOfSecret (`_id`)',
    lists: [{ method: 'GET', path: /^\/environment\/secrets$/ }],
    fields: ['_id'],
  },
  {
    name: 'cloud: secret versions',
    functions: 'deleteVersionOfSecret, pruneVersionsOfSecret (listed `version`)',
    lists: [{ method: 'GET', path: /^\/environment\/secrets\/[^/]+\/versions$/ }],
    fields: ['version'],
  },
  {
    name: 'cloud: variables',
    functions: 'deleteVariable (`_id`)',
    lists: [{ method: 'GET', path: /^\/environment\/variables$/ }],
    fields: ['_id'],
  },
  {
    name: 'cloud: certificates',
    functions: 'deleteCertificate, deleteCertificates (listed `_id`)',
    lists: [{ method: 'GET', path: /^\/environment\/certificates$/ }],
    fields: ['_id', 'id'],
  },
  {
    name: 'cloud: CSRs',
    functions: 'deleteCSR, deleteCSRs (listed `_id`)',
    lists: [{ method: 'GET', path: /^\/environment\/csrs$/ }],
    fields: ['_id', 'id'],
  },
  {
    name: 'cloud: log API keys',
    functions: 'deleteLogApiKey, deleteLogApiKeys (listed `api_key_id`)',
    lists: [{ method: 'GET', path: /^\/keys$/ }],
    fields: ['api_key_id'],
  },
  {
    name: 'cloud: telemetry exporters',
    functions: 'deleteTelemetry (listed `id` of an exporter)',
    lists: [{ method: 'GET', path: /^\/environment\/telemetry$/, object: true }],
    fields: ['id'],
  },
  {
    name: 'IGA: certification templates',
    functions: 'deleteCertificationTemplate(s)(ByName) (listed `id`)',
    lists: [
      { method: 'GET', path: /^\/iga\/governance\/certification\/template$/ },
      { method: 'POST', path: /^\/iga\/governance\/certification\/template\/search$/ },
    ],
    fields: ['id', '_id'],
  },
  {
    name: 'IGA: events',
    functions: 'deleteEvent(s)(ByName) (listed `id`)',
    lists: [{ method: 'GET', path: /^\/iga\/governance\/event$/ }],
    fields: ['id', '_id'],
  },
  {
    name: 'IGA: glossary schemas',
    functions: 'deleteGlossarySchema(s), deleteGlossarySchemaByNameAndObjectType (listed `id`)',
    lists: [{ method: 'POST', path: /^\/iga\/commons\/glossary\/schema\/search$/ }],
    fields: ['id', '_id'],
  },
  {
    name: 'IGA: request forms',
    functions: 'deleteRequestForm(s)(ByName) (listed `id`)',
    lists: [{ method: 'GET', path: /^\/iga\/governance\/requestForms$/ }],
    fields: ['id', '_id'],
  },
  {
    name: 'IGA: request types',
    functions: 'deleteRequestType(s)(ByName) (listed `id`)',
    lists: [{ method: 'GET', path: /^\/iga\/governance\/requestTypes$/ }],
    fields: ['id', '_id'],
  },
  {
    name: 'IGA: workflows',
    functions: 'deleteWorkflow(s), deleteDraftWorkflow, deletePublishedWorkflow (listed `id`)',
    lists: [{ method: 'GET', path: /^\/iga\/governance\/workflow$/ }],
    fields: ['id', '_id'],
  },
  {
    name: 'secret stores',
    functions: 'deleteSecretStore(s) (listed `_id`, `_type._id`; the id of a singleton type is not sent)',
    lists: [
      { method: 'POST', path: new RegExp(`^${RC}/secrets/stores$`), action: /^nextdescendents$/ },
      { method: 'POST', path: new RegExp(`^${GC}/secrets/stores$`), action: /^nextdescendents$/ },
    ],
    fields: ['_id'],
    typeField: true,
  },
  {
    name: 'secret store mappings',
    functions: 'deleteSecretStoreMapping(s) (listed `_id` of a mapping)',
    lists: [
      { method: 'GET', path: new RegExp(`^${RC}/secrets/stores/[^/]+/[^/]*/mappings$`) },
      { method: 'GET', path: new RegExp(`^${GC}/secrets/stores/[^/]+/[^/]*/mappings$`) },
    ],
    fields: ['_id'],
  },
  {
    name: 'OAuth2 clients',
    functions: 'deleteOAuth2Clients (listed `_id`)',
    lists: [{ method: 'GET', path: new RegExp(`^${RC}/agents/OAuth2Client$`) }],
    fields: ['_id'],
  },
  {
    name: 'trusted JWT issuers',
    functions: 'deleteOAuth2TrustedJwtIssuers (listed `_id`)',
    lists: [{ method: 'GET', path: new RegExp(`^${RC}/agents/TrustedJwtIssuer$`) }],
    fields: ['_id'],
  },
  {
    name: 'policies',
    functions: 'deletePolicy (typed `_id`)',
    lists: [{ method: 'GET', path: new RegExp(`^/am/json${REALM}/policies$`) }],
    fields: ['_id'],
  },
  {
    name: 'policy sets',
    functions: 'deletePolicySet (typed `name`)',
    lists: [{ method: 'GET', path: new RegExp(`^/am/json${REALM}/applications$`) }],
    fields: ['name'],
  },
  {
    name: 'resource types',
    functions: 'deleteResourceType, deleteResourceTypeByName (listed `uuid`)',
    lists: [{ method: 'GET', path: new RegExp(`^/am/json${REALM}/resourcetypes$`) }],
    fields: ['uuid'],
  },
  {
    name: 'realms',
    functions: 'deleteRealm, deleteRealmByName (listed `_id`)',
    lists: [{ method: 'GET', path: /^\/am\/json\/global-config\/realms\/?$/ }],
    fields: ['_id'],
  },
  {
    name: 'circles of trust',
    functions: 'deleteCircleOfTrust, deleteCirclesOfTrust (listed `_id`)',
    lists: [{ method: 'GET', path: new RegExp(`^${RC}/federation/circlesoftrust$`) }],
    fields: ['_id'],
  },
  {
    name: 'social identity providers and admin federation providers',
    functions: 'deleteSocialIdentityProvider(s), deleteAdminFederationProvider (listed `_id`)',
    lists: [{ method: 'POST', path: new RegExp(`^${RC}/services/SocialIdentityProviders$`), action: /^nextdescendents$/ }],
    fields: ['_id'],
  },
  {
    name: 'SAML2 providers (the stub `_id`, base64)',
    functions: 'deleteSaml2Provider, deleteSaml2Providers (listed stub `_id`; the entity id is a URL and is not checked)',
    lists: [{ method: 'GET', path: new RegExp(`^${RC}/saml2$`) }],
    fields: ['_id'],
  },
  {
    name: 'applications (managed objects)',
    functions: 'deleteApplication(s)(ByName) (listed `_id`)',
    lists: [{ method: 'GET', path: /^\/openidm\/managed\/[a-z]*_?application$/ }],
    fields: ['_id'],
  },
  {
    name: 'managed objects',
    functions: 'deleteManagedObjects, deleteManagedSystemObjects (listed `_id` of a queried page)',
    lists: [{ method: 'GET', path: /^\/openidm\/managed\/[^/]+$/ }],
    fields: ['_id'],
  },
  {
    name: 'system objects',
    functions: 'deleteSystemObject (typed; the ids that a query lists)',
    lists: [{ method: 'GET', path: /^\/openidm\/system\/[^/]+\/[^/]+$/ }],
    fields: ['_id'],
  },
  {
    name: 'internal roles',
    functions: 'deleteInternalRole(s)(ByName) (listed `_id`)',
    lists: [{ method: 'GET', path: /^\/openidm\/internal\/role$/ }],
    fields: ['_id'],
  },
];

function* walk(dir) {
  for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
    const p = path.join(dir, e.name);
    if (e.isDirectory()) yield* walk(p);
    else if (e.name.endsWith('.har')) yield p;
  }
}
function bodyOf(entry) {
  const c = entry.response && entry.response.content;
  if (!c || typeof c.text !== 'string' || c.text === '') return undefined;
  let t = c.text;
  if (c.encoding === 'base64') t = Buffer.from(t, 'base64').toString('utf8');
  try {
    return JSON.parse(t);
  } catch {
    return undefined;
  }
}
function itemsOf(body, spec) {
  if (spec.object && body && typeof body === 'object' && !Array.isArray(body)) {
    return Object.values(body).filter(Array.isArray).flat();
  }
  if (Array.isArray(body)) return body;
  if (!body || typeof body !== 'object') return [];
  for (const key of ['result', 'configurations', 'keys', 'data', 'items', 'results']) {
    if (Array.isArray(body[key])) return body[key];
  }
  return [];
}

const stats = new Map(FAMILIES.map((f) => [f.name, { answers: 0, ids: 0, distinct: new Set(), refused: new Set() }]));
// every DELETE request: a segment of its path after the first that the rule refuses (an empty last segment is the singleton secret store)
const deleteSegments = { requests: 0, refused: new Map() };
let nfiles = 0;
let nentries = 0;
for (const root of process.argv.slice(2)) {
  for (const file of walk(root)) {
    nfiles++;
    let har;
    try {
      har = JSON.parse(fs.readFileSync(file, 'utf8'));
    } catch {
      continue;
    }
    for (const entry of har.log.entries) {
      nentries++;
      const { method, url } = entry.request;
      let u;
      try {
        u = new URL(url);
      } catch {
        continue;
      }
      if (method === 'DELETE') {
        deleteSegments.requests++;
        const segments = u.pathname.split('/').slice(1);
        segments.forEach((segment, index) => {
          let decoded = segment;
          try {
            decoded = decodeURIComponent(segment);
          } catch {
            // an escape that does not decode is checked as it is
          }
          if (!isRequestSegment(decoded)) {
            const shown = decoded === '' && index === segments.length - 1 ? '(an empty last segment)' : JSON.stringify(decoded);
            deleteSegments.refused.set(shown, (deleteSegments.refused.get(shown) ?? 0) + 1);
          }
        });
      }
      for (const family of FAMILIES) {
        for (const spec of family.lists) {
          if (spec.method !== method || !spec.path.test(u.pathname)) continue;
          const action = u.searchParams.get('_action');
          if (spec.action && !(action && spec.action.test(action))) continue;
          const items = itemsOf(bodyOf(entry), spec);
          if (!items.length) continue;
          const s = stats.get(family.name);
          s.answers++;
          for (const it of items) {
            if (!it || typeof it !== 'object') continue;
            const values = family.fields.map((f) => it[f]).filter((v) => typeof v === 'string');
            if (family.typeField && it._type && typeof it._type._id === 'string') values.push(it._type._id);
            for (const v of values) {
              s.ids++;
              s.distinct.add(v);
              // the id of the one singleton secret store is not sent, so it is not checked (the id of the type is)
              if (!isRequestSegment(v)) s.refused.add(v);
            }
          }
        }
      }
    }
  }
}
console.log(`files ${nfiles}, entries ${nentries}`);
for (const f of FAMILIES) {
  const s = stats.get(f.name);
  console.log(`${f.name}\t${s.answers}\t${s.ids}\t${s.distinct.size}\t${s.refused.size}${s.refused.size ? '\t' + [...s.refused].slice(0, 8).map((x) => JSON.stringify(x)).join(' ') : ''}`);
}
console.log(`DELETE requests ${deleteSegments.requests}; segments that the rule refuses: ${[...deleteSegments.refused].map(([s, n]) => `${s} x${n}`).join(', ') || 'none'}`);

Verification

  • npm run check: exit 0. npx tsc --noEmit: exit 0, and tsc over the changed test files (DeleteFunctions.requestPath, DeleteFunctions.bulkItems, the two errorWrapping tests and src/test): exit 0. npm run build: exit 0 and git status clean afterwards (src/lib/Help.ts is unchanged: the new documentation is in @throws lines).
  • Tests: npm run test:only -- src/ops/DeleteFunctions and -- src/ops/internal/RequestPathIds pass; the whole suite: npm test (exit 0): 474 suites passed and 1 skipped, 17723 tests passed, 10 skipped, 10 todo, 1040 snapshots passed; git status clean afterwards (measured before the last commit, which adds three tests to the walk).
  • Negative proofs: every check was removed in turn (65 places), six were moved below the first read (deleteCertificate, deleteApplication on IGA, deleteRequestForm, deleteLogApiKey, pruneVersionsOfSecret, deleteJourney below the progress indicator), and the rule of the secret store id was changed three ways (checked for every type, never checked, no type exempt): none of them survives. For the checks of the second round 17 more were run, and each fails at least one test: the filter that skips the deactivation of a refused certificate taken out, the check of deleteCertificate taken out, the type checks of deleteManagedObjects, deleteManagedSystemObject and deleteManagedSystemObjects taken out, the workflow id check taken out, moved below the first read and made unconditional, the type check of deleteSecretStore, deleteSecretStoreMapping and deleteSecretStoreMappings made unconditional, deleteCustomNode checking the id as given instead of the one that is sent, the not-found branch of deleteScriptByName taken out, the check of a container node and the check of a listed AI agent id taken out, and the row and the exemption of deleteOrphanedRequestFormAssignments (removed, or both present). Four tests were added after the first run showed a check that nothing tested (the version of a node type, the ops deleteSecret, the typed ids of deleteSecretStoreMappings, deleteWorkflow with a result callback).
  • Two existing tests are changed, nothing is weakened in either. ScriptOps.errorWrapping.unit.test.ts, the row of deleteScriptByName: the function now reads the script by its name and deletes it by the id that the tenant lists (it called one api function that did both, which the ops layer no longer calls; the api function itself is unchanged), so the row has two cases, the read fails and the delete fails, with the same message. ManagedSystemObjectOps.errorWrapping.unit.test.ts, the row of deleteManagedSystemObject: it passed the type system/ldap/account, which is not a type of that function and is not one name; it passes teammember and expects Error deleting managed teammember object (u1). No recording and no snapshot is touched.
  • Not verified: nothing was run against a tenant. A refusal sends nothing, so there is no request to record.

Risks

  • A caller that gave an id that is not one name (undefined, an id with a slash) is now refused instead of sent. The recorded lists and DELETE requests hold no such id.
  • A listed id that the rule refuses (the list answers of a tenant that the recordings do not show) is one failed item and is not deleted; it is reported without the id.
  • deleteCertificates with force no longer deactivates a certificate with such an id; if that certificate is the only one, the wait for the certificates to go offline ends at its own timeout, besides the refusal. No recorded list holds such an id.

What the maintainer has to do

Review the rule of assertSecretStoreId, the list of exempt functions and the MIGRATION.md entry, which now covers every delete function.

🤖 Generated with Claude Code

vscheuber and others added 6 commits November 29, 2026 11:44
assertSecretStoreId checks the id of a secret store unless the store is of
the type that has one store and no id: the request for such a store names
the type and ends there, so its id is not sent and is not checked. The type
is checked by assertRequestSegment. Internal, not on the facade.

Refs #1192

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The delete functions of agents, journeys and nodes, scripts, the cloud
environment (secrets and their versions, variables, certificates, CSRs, log
API keys, telemetry, signing keys and IdP adapters), IGA (certification
templates, events, glossary schemas, request forms and types, workflows),
secret stores and their mappings, OAuth2 clients, trusted issuers, policies,
policy sets, resource types, realms, circles of trust, social identity
providers, SAML2 providers, applications, managed and system objects and
internal roles check the id before they send any request, as those of IDM
config and services do. A function that deletes what a list holds checks each
listed id as one item, so a refused id is one failed item like a delete that
fails with HTTP 500. The facade walk lists no function as pending any more;
the scenarios of the lists run each function twice, with a refused id and with
a failing one, and compare what was deleted and what was reported.

Refs #1192

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…y delete function

Refs #1192

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…sted

The facade cannot give deleteNode a version, and does not call the ops
function deleteSecret; deleteSecretStoreMappings, pruneVersionsOfSecret,
deleteWorkflow with a result callback and deleteCustomNode by its display
name need ids of their own. The check of the secret id of a version is made
once, when the prune begins.

Refs #1192

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Refs #1192

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@vscheuber vscheuber added the no-auto-processing Concierge never touches this item; remove the label to hand it over label Nov 29, 2026
vscheuber and others added 9 commits November 29, 2026 12:52
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The catch of a rejected call and the print handler of the journey test had types that tsc over the test files refuses. Nothing is asserted differently.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
deleteJourneys was listed with the functions that try every item and throw one error after the last one. It resolves with the status of each journey, a refused or failed journey has status error and an error, and a result callback gets no error argument.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…on and reads included

deleteCertificates with force sent a PATCH to deactivate an active certificate that the tenant listed with such an id before the delete refused it, deleteJourney read a container node by such an id before the node was deleted, and deleteAIAgents sent the listed id in the filter of a read. Each is now checked before the first request for it: the certificate is skipped by the deactivation and refused by its delete, the container node is a failed node that is not read, and the agent is refused before it is looked up.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…a custom node and a script that is not found

deleteSecretStore, deleteSecretStoreMapping and deleteSecretStoreMappings without a type find the type and delete. deleteCustomNode checks and sends the id with the -1 that it adds. deleteScriptByName for a name that no script has fails with the text it had and deletes nothing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The workflow id goes into the path of the two reads that look up the workflows, so it is checked first, before any request. No id goes into the path of the removal: it is a POST built from what the tenant lists, and the filters that the other ids go into are out of scope. The function has a row in the walk now and is no longer exempt.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…t and deleteManagedSystemObjects

The type goes into the path of the query that reads the objects and of each delete, so it is checked before the first request. The real values (alpha_user, svcacct, teammember) are one name each. The mocked test of deleteManagedSystemObject passed a type with slashes, which is no type of that function; it passes teammember now.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ete functions and of a comment

"A listed X that the tenant lists" said list twice and "A event" had the wrong article; the sentences of the single deletes of an object that is found by a name say that no delete request is sent. The comment on the secret store types that have no id says only what the code does.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…xt of a refused container node and an empty workflow id

deleteCertificates with force on a list of active, inactive and refused certificates deactivates only the active ones with a good id, deletes every good one and sends nothing for a refused one. The verbose text for a container node whose id is not one name holds no id. An empty workflow id of deleteOrphanedRequestFormAssignments is none: it is not refused and sends what a call without a workflow id sends.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@vscheuber
vscheuber merged commit 22ec7e2 into main Nov 30, 2026
17 checks passed
@vscheuber
vscheuber deleted the fix/library-delete-functions-check-ids-2 branch November 30, 2026 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-auto-processing Concierge never touches this item; remove the label to hand it over

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant