Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 11 min read

The workspace ID in the URL never reached the team being deleted

There is a particular kind of bug that only shows up when you read a route and its use case as two separate documents. The route authorizes one thing. The use case mutates another. Both are correct in isolation. C03 was

There is a particular kind of bug that only shows up when you read a route and its use case as two separate documents. The route authorizes one thing. The use case mutates another. Both are correct in isolation.

C03 was the only finding in the October audit of internxt/drive-server-wip that got fixed after I escalated to CERT-Bund. It sat in triage from 28 October until 20 November. On that day a maintainer merged PR #1297 with the line "Fixes GHSA-wjmx-m49r-9rrh", published the advisory as Moderate, closed and locked the issue I had been asking questions in, and moved several other advisories at once. I had spent three weeks watching commits land on master almost every working day β€” index cleanups, performance work, client-version policies, a photos bucket β€” while this one stayed untouched.

The route is DELETE /workspaces/:workspaceId/teams/:teamId. Its decorators are explicit about who may call it, and the controller hands the use case only the second of its two parameters:

  @ApiBearerAuth()
  @ApiOkResponse({
    description: 'Deleted team',
  })
  @UseGuards(WorkspaceGuard)
  @WorkspaceRequiredAccess(AccessContext.WORKSPACE, WorkspaceRole.OWNER)
  async deleteTeam(
    @Param('teamId', ValidateUUIDPipe) teamId: WorkspaceTeamAttributes['id'],
  ) {
    return this.workspaceUseCases.deleteTeam(teamId);
  }

  @Post('/teams/:teamId/user/:userUuid')

WorkspaceGuard plus @WorkspaceRequiredAccess(AccessContext.WORKSPACE, WorkspaceRole.OWNER). The guard reads the workspaceId from the URL and checks that the caller is an owner of that workspace. That is a real authorization decision. The problem is what happens to it next: the controller passes only teamId to the use case. The workspace ID that was just authorized never leaves the controller.

The use case is five lines:

  async deleteTeam(teamId: WorkspaceTeam['id']) {
    await this.getAndValidateNonDefaultTeamWorkspace(teamId);

    await this.teamRepository.deleteTeamById(teamId);
  }

getAndValidateNonDefaultTeamWorkspace(teamId) resolves the team by its ID, loads the workspace the team record points at, and validates against that workspace β€” not against the URL. It also rejects the default team, which is why the helper exists at all. So there are two workspaces in play: the guard validates the one in the URL, the validator loads the one the team belongs to, and nothing compares them. deleteTeamById(teamId) then removes the row. If you own workspace A and know the UUID of a non-default team in workspace B, the A-authorized URL is enough.

The same pattern showed up in the manager and role-change branches, where findWorkspaceUser was called with memberId and deactivated but no workspace predicate:

    const { team } = await this.getAndValidateNonDefaultTeamWorkspace(teamId);

    const workspaceUser = await this.workspaceRepository.findWorkspaceUser({
      memberId,
      deactivated: false,
    });

I did not exercise the manager-role branch in the PoC, and I said so in the report. A finding should state exactly what was run and what was only read.

The workspace domain makes the mistake easy to miss. A workspace has an owner, members, and teams; a team has a manager and members of its own; there is a default team that cannot be deleted. The decorator on the route checks the OWNER role against the workspace named in the URL, so the guard resolves the caller's role correctly. That is why this bug is not simply "no authorization". The authorization exists. It is bound to the wrong object.

Reading the use case makes the mismatch look almost reasonable, which is what worried me:

  async getAndValidateNonDefaultTeamWorkspace(teamId: string) {
    const team = await this.teamRepository.getTeamById(teamId);

    if (!team) {
      throw new BadRequestException('Team not found');
    }

    const workspace = await this.workspaceRepository.findOne({
      id: team.workspaceId,
    });

    if (!workspace) {
      throw new ForbiddenException('Not valid workspace found');
    }

    if (workspace.isDefaultTeam(team)) {

getAndValidateNonDefaultTeamWorkspace exists to stop you from deleting the default team, and it does that job well: resolve the team, load its workspace, refuse if this is the default team of that workspace. Every line inside it is defensible. The function was written for a world in which the caller had already been scoped to the right workspace β€” and the route above it simply never established that. Contracts like that are invisible in a diff review of either file, because neither file contains the mistake. The mistake is the gap between them, and the gap is only visible when you read both in one sitting.

What tipped me off was not an error message or a failing test. It was the shape of the controller method: two path parameters in the URL, one of them used only by decorators. When a :workspaceId appears in a route and never appears in the method body or the call it makes, that is worth ten minutes of reading. I opened the use case expecting to find workspaceId somewhere down the stack. It was not there. The validator resolved a workspace from the team record instead, which is a perfectly sensible thing to do if you assume the team was already scoped β€” and that assumption is exactly what the guard did not establish.

This is also why I wrote the PoC with two complete workspaces rather than one team with a forged ID. A single workspace would have made the bug invisible: the URL workspace and the team workspace would have been the same object, and the delete would have looked authorised. Two owners, two workspaces, one cross-workspace team ID. The test has to create the disagreement, because the disagreement is the vulnerability.

  it('C03: A owner can delete a nondefault team in B through the A workspace URL', async () => {
    const ownerA = await createTestUser(app);
    const ownerB = await createTestUser(app);
    const a = await workspaceFor(ownerA);
    const b = await workspaceFor(ownerB);
    const teamB = await teams.create({ id: v4(), workspaceId: b.id, managerId: ownerB.user.uuid, name: 'B-local-team' } as any);
    const res = await request(app.getHttpServer())
      .delete(`/workspaces/${a.id}/teams/${teamB.id}`)
      .set('Authorization', `Bearer ${ownerA.token}`);
    expect(res.status).toBe(200);
    expect(await teams.findByPk(teamB.id)).toBeNull();
  });

Two assertions:

    expect(res.status).toBe(200);
    expect(await teams.findByPk(teamB.id)).toBeNull();

HTTP 200, and the B team row was gone. A 200 is the wrong status code for a delete you were never entitled to, but it is an honest one: the server had no reason to think anything was missing. The guard had approved workspace A, the validator had approved the team, and nothing in between had ever compared the two. The request log shows a perfectly ordinary owner deleting a perfectly ordinary team; the fact that the team belonged to someone else's workspace is nowhere in it. That is also what makes this class of bug survive in the wild β€” there is no error, no alert, no failed request to notice. Just a missing row in a database, and an owner who eventually wonders where their team went.

For the team's members, the effect would be ordinary in the worst way. A team in this backend groups workspace members with a shared role and a manager; deleting the row dissolves the grouping without touching anyone's files. Nothing is stolen, nothing is read, and the workspace owner's next visit shows a team that simply is not there anymore. No notification is sent for a deletion performed through another workspace's URL, because as far as the code is concerned, no rule was broken. Disappearance without a trace is a peculiar kind of impact to write up: there is nothing to exfiltrate and no confidentiality boundary crossed, and yet the integrity of someone else's workspace structure was modified by a stranger. The Moderate rating on the published advisory is, I think, a fair answer to that.

Everything ran on commit 7d7a8be2 against disposable PostgreSQL and Valkey, with synthetic fixtures and no route to anything else, through the same loopback-only harness as the other twelve findings: a staged test file removed by a trap on exit, synthetic credentials, SendGrid in sandbox mode, and the 127.0.0.1 guard at the top of the PoC's beforeAll. The four-line test-only patch for the mock Bridge provider's missing getLimit() is documented in the harness post, not with the finding.

I filed C03 on 28 October as one of the first three private advisories, alongside C01 and C02. For the next three weeks the repository moved and the advisory did not. On 4 November I offered to open pull requests. On 19 November I asked why nobody was answering. On 20 November the answer arrived as a merge:

@@ -2568,8 +2570,15 @@ export class WorkspacesUsecases {
     await this.teamRepository.updateById(team.id, { managerId });
   }

-  async deleteTeam(teamId: WorkspaceTeam['id']) {
-    await this.getAndValidateNonDefaultTeamWorkspace(teamId);
+  async deleteTeam(
+    workspaceId: WorkspaceAttributes['id'],
+    teamId: WorkspaceTeam['id'],
+  ) {
+    const { team } = await this.getAndValidateNonDefaultTeamWorkspace(teamId);
+

@@ -2617,7 +2626,7 @@ export class WorkspacesUsecases {
       this.teamRepository.getTeamUser(userUuid, teamId),
     ]);

-    if (!team) {
+    if (team?.workspaceId !== workspaceId) {

PR #1297 threads workspaceId from the route into deleteTeam, rejects a mismatch with BadRequestException('Team not found'), scopes findWorkspaceUser by team.workspaceId in both the manager and role-change branches, and tightens changeUserRole with team?.workspaceId !== workspaceId. It is a careful fix. A code owner approved it, SonarQube reported zero new issues and 88.9% coverage on the new code, and cross-workspace regression tests came with it β€” one of them constructs a team in another workspace, mocks the repository, and asserts that the role change is refused:

    it('When the team belongs to another workspace, then error is thrown and role is not changed', async () => {
      const team = newWorkspaceTeam({ workspaceId: v4() });
      jest.spyOn(teamRepository, 'getTeamById').mockResolvedValue(team);
      jest
        .spyOn(teamRepository, 'getTeamUser')
        .mockResolvedValue(newWorkspaceTeamUser({ teamId: team.id }));

      const result = service.changeUserRole(v4(), team.id, 'userId', {
        role: WorkspaceRole.MANAGER,

Whoever picked this up on 20 November did it properly. The three weeks before that are the part I have no explanation for, and I would rather say that plainly than invent one.

That same day also produced everything else at once: the issue was locked to collaborators and closed as completed, C08 was published after twenty-two days, C09 and C11 were closed without a published fix or a stated reason, and the one-sentence acknowledgement was posted. A queue that had been still for three weeks moved five things in an afternoon. I would like to be able to say what triggered that, because a researcher holding eleven other findings on a disclosure clock needs to know whether the trigger was an email, a CERT, a sprint, or nothing at all. From the outside it is one indistinguishable event, and the full day is laid out in the timeline post.

One detail about the advisory page itself is worth knowing, because it makes C03 look unfixed to anyone who checks only there. The published advisory still carries the 28 October description β€” no updated summary, placeholder entries in the version fields, and no mention of the patch. The fix is documented in the pull request and the merge commit, not in the advisory that describes the vulnerability. Cross-check the advisory against master and the fix is there; read the advisory alone and you could reasonably conclude nothing was ever addressed.

The part I still cannot explain is the selection. C01 and C02, both rated High, remain in triage without a maintainer response. C09 and C11 were closed on the same 20 November without a published fix or a stated reason. C03, rated Moderate, was the one that got a patch and a published advisory. There may be a completely ordinary reason β€” a sprint boundary, a ticket someone picked up, a queue finally being read from top to bottom. From the outside it looks arbitrary, and arbitrary is a difficult thing to plan around when you are holding eleven other findings on a disclosure clock.

I had escalated to CERT-Bund, Germany's national CERT at the BSI, in early November. On 11 November their reading was fair: since some issues had already been fixed, there was no reason to assume the rest would not be. They asked for a status update on 24 November. On 20 November I emailed Internxt a disclosure schedule β€” 1 December 2026 for the timeline and the fixed issues, 18 January 2027 for full technical details, ninety days after my first email. On the same day, the movement happened. I am not claiming causation. I am describing a sequence, because the sequence is the only data I have.

The technical rule is short: bind the identifier that was authorized to the row that gets mutated. A guard on the URL is a check on the URL, not on the target. It is the same family as the C07 bug, where a delete ran before an ownership check, and it is the family that IDOR findings have lived in for twenty years. What makes it hard to spot in a NestJS codebase is that the two halves look fine in their own files. The controller has guards. The use case has a validator. You have to hold both in your head at once to notice that they are talking about different objects.

In review, the question that catches this class is not "is there a guard?" but "which object did the guard authorize, and is that the object being changed?". It reads as pedantry until the one time the two answers differ. The habit costs a few seconds per route: look at the path parameters, look at what the handler passes downstream, and check that the parameter consumed by authorization is the same parameter that reaches the repository call. In this route it took one line β€” deleteTeam(workspaceId, teamId) instead of deleteTeam(teamId) β€” to make the two halves agree, and one line in the validator to enforce it. The fix being that small is not a comfort; it is the measurement of how early the mistake should have been caught.

The other rule is about triage rather than code. A queue that moves three weeks late, on the day an issue is locked, and fixes the Moderate finding while two High ones stay untouched, gives a researcher nothing to plan with. An acknowledgement, a named contact and a rough timeline would have cost less than the PR. Fixing the code was never the expensive part.

The disclosure schedule still stands: 1 December 2026 for the timeline and full details of the fixed issues, 18 January 2027 for the remaining findings. I have no evidence this was exploited. The advisory is open, the PoC is attached, and I am happy to verify fixes β€” including the manager-role branch I did not exercise.

References: GHSA-wjmx-m49r-9rrh, PR #1297, issue #1246.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.