Skip to content

fix: allow legitimate instanceName input on instance create and fetch routes - #2735

Open
maonamassaaceleradora wants to merge 2 commits into
evolution-foundation:developfrom
Mao-na-Massa-Aceleradora-Digital:fix/instance-routes-input-sanitization
Open

maonamassaaceleradora wants to merge 2 commits into
evolution-foundation:developfrom
Mao-na-Massa-Aceleradora-Digital:fix/instance-routes-input-sanitization

Conversation

@maonamassaaceleradora

@maonamassaaceleradora maonamassaaceleradora commented Sep 21, 2026 •

Copy link
Copy Markdown

📋 Description

The cross-instance auth bypass fix in 7a55a2bf added sanitizeUntrustedInput(), which strips instanceName and instanceId from any untrusted body or query string. That is the right default for the vast majority of routes, which carry :instanceName in their path and read the instance from request.params — there, a body or query copy of those fields can only ever be an override attempt.

Two instance routes have no path parameter, and for them the sanitizer removes legitimate, required input.

1. POST /instance/create — creating an instance became impossible

There is no :instanceName in this route's path, so the name can only come from the body. The sanitizer stripped it, leaving the create request with no name at all:

  • first as a Prisma 500 — Argument 'name' is missing
  • then, once the name was defaulted upstream of that, as a 400 — The instanceName cannot be empty

2. GET /instance/fetchInstances?instanceName=X — filter silently ignored

Same root cause, but the failure mode is quieter and arguably worse. The filter was stripped from the query string, and the request still returned 200 — just with every instance on the server rather than the one that was requested. There is no error for a caller to notice; a filtered lookup silently became a full listing.

The fix

sanitizeUntrustedInput() takes the protected field list as a parameter, defaulting to the existing PROTECTED_INSTANCE_FIELDS, so each call site can declare what it actually needs:

  • /instance/create → ['instanceId']
  • /instance/fetchInstances → [] (query string only)
  • every other route → the full default list, unchanged

This does not reopen the 7a55a2bf bypass

Worth being explicit, since this PR relaxes a security fix:

  • /instance/create still protects instanceId. That is the field that matters there — it is server-generated, and letting a caller choose it is what would allow colliding with or hijacking an existing instance. instanceName on this route is not an override of a trusted path parameter; it is the sole source of the value, and it is validated and uniqueness-checked downstream as before.
  • /instance/fetchInstances is a read-only lookup with no :instanceName to override. The bypass 7a55a2bf closed was one where a body/query field overrode an instance identity already established by the path — which cannot happen on a route that has no such parameter.
  • No route that has :instanceName in its path had its protection changed. The default is untouched, so every route that was hardened by 7a55a2bf stays hardened.

🔗 Related Issue

No issue filed. Follow-up to 7a55a2bf; found on one of our production instances immediately after picking up that commit.

🧪 Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧹 Code cleanup
  • 🔒 Security fix

🧪 Testing

  • Manual testing completed
  • Functionality verified in development environment
  • No breaking changes introduced
  • Tested with different connection types (if applicable)

Verified against one of our production instances:

  • POST /instance/create — before: 500 from Prisma / 400 The instanceName cannot be empty. After: the instance is created with the requested name.
  • GET /instance/fetchInstances?instanceName=X — before: 200 with every instance on the server. After: 200 with only the requested instance.
  • GET /instance/fetchInstances with no filter still returns the full listing.
  • Passing instanceId in the body of /instance/create is still rejected and still logs the "Ignoring attempt to override protected field" warning.
  • Spot-checked routes that do carry :instanceName to confirm body/query overrides are still stripped.
  • npm run lint:check and npx tsc --noEmit both pass with no errors.

✅ Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have manually tested my changes thoroughly
  • I have verified the changes work with different scenarios
  • Any dependent changes have been merged and published

📝 Additional Notes

The two commits are split by route so they can be reviewed independently — the /instance/create breakage is the louder one, but the fetchInstances filter being dropped silently is the one more likely to have gone unnoticed in the wild.

If you would rather see the allowed fields expressed as an explicit per-route map instead of the optional parameter used here, I'm happy to restructure it that way.

🤖 Generated with Claude Code

Summary by Sourcery

Restore legitimate instance creation and filtered lookup inputs without weakening protection for routes that establish instance identity through the path.

Bug Fixes:

  • Allow instance creation to accept the requested instance name while continuing to reject caller-supplied instance IDs.
  • Preserve instance-name and instance-ID filters for the instance listing route instead of silently dropping them.

Enhancements:

  • Make protected-input sanitization configurable per route while retaining the existing protected-field defaults for other routes.

The cross-instance auth bypass fix (7a55a2b) strips instanceName and
instanceId from any untrusted body or query via sanitizeUntrustedInput().

Every other instance route carries ":instanceName" in its path, so the name
is read from request.params and stripping the body copy is correct. But
/instance/create has no path parameter — the name can only ever come from the
body, so the sanitizer removed the one required field of the request.

That surfaced first as a Prisma 500 ("Argument `name` is missing") and, after
the name was defaulted, as a 400 "The instanceName cannot be empty". Creating
an instance was impossible.

Parameterize the protected field list so each call site declares what it
needs, and pass ['instanceId'] on /instance/create. This does not reopen the
bypass: instanceId is server-generated and stays protected, and every other
route keeps the full default list.
…ances

GET /instance/fetchInstances?instanceName=X is a lookup route: like
/instance/create it has no ":instanceName" in its path, so its filter can only
arrive in the query string.

sanitizeUntrustedInput() stripped both instanceName and instanceId from the
query, and did so silently from the caller's point of view — the request still
returned 200, just with every instance on the server instead of the one that
was asked for. A filtered lookup silently turning into a full listing is worse
than an error.

Allow both fields through for this route only; every other route keeps the
default protected list.
@sourcery-ai

sourcery-ai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR parameterizes untrusted-input sanitization to account for routes where instance identity legitimately comes from the request body or query string: instance creation accepts instanceName but still protects server-generated instanceId, while fetchInstances preserves query filters. The sanitizer’s default remains unchanged, so routes with :instanceName continue rejecting body/query identity overrides.

Sequence diagram for route-specific instance input sanitization

sequenceDiagram
    participant Client
    participant RouterBroker
    participant Sanitizer
    participant InstanceService

    Client->>RouterBroker: POST /instance/create with instanceName
    RouterBroker->>Sanitizer: sanitizeUntrustedInput(body, ['instanceId'])
    Sanitizer-->>RouterBroker: instanceName retained, instanceId rejected
    RouterBroker->>InstanceService: Create instance with instanceName
    InstanceService-->>Client: Created instance

    Client->>RouterBroker: GET /instance/fetchInstances?instanceName=X
    RouterBroker->>Sanitizer: sanitizeUntrustedInput(query, [])
    Sanitizer-->>RouterBroker: instanceName filter retained
    RouterBroker->>InstanceService: Fetch instances filtered by instanceName
    InstanceService-->>Client: Matching instances

    Client->>RouterBroker: Request route with :instanceName and query override
    RouterBroker->>Sanitizer: sanitizeUntrustedInput(query)
    Sanitizer-->>RouterBroker: instanceName and instanceId rejected
Loading

Flow diagram for protected instance fields by route

flowchart TD
    A[Untrusted body or query input] --> B{Route has special input rules?}
    B -->|POST /instance/create| C[sanitizeUntrustedInput with instanceId protected]
    C --> D[Allow instanceName; reject instanceId]
    B -->|GET /instance/fetchInstances| E[sanitizeUntrustedInput with no protected fields]
    E --> F[Preserve instanceName or instanceId filters]
    B -->|Other routes| G[sanitizeUntrustedInput with default protected fields]
    G --> H[Reject instanceName and instanceId overrides]
Loading

File-Level Changes

Change Details Files
Make protected-field sanitization configurable per route while preserving the existing secure default.
  • Add an optional protected-field list to the sanitizer, defaulting to both instance identity fields.
  • Allow the create route to accept body-supplied instanceName while continuing to reject instanceId.
  • Allow fetchInstances query filters through because the route has no path-based instance identity.
  • Keep all other routes on the original protection behavior.
src/api/abstract/abstract.router.ts
Restore legitimate instance creation and filtered instance lookup behavior without weakening path-based override protection.
  • Merge the sanitized create body so requested names reach downstream validation and uniqueness checks.
  • Avoid stripping fetchInstances query parameters, including instanceName and instanceId, so filtering remains effective.
  • Use route detection based on the original URL to apply the exceptions.
src/api/abstract/abstract.router.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. This changes which untrusted query and body fields can determine the target instance, so an incorrect protection decision could select or create the wrong instance and potentially expose or persist data under the wrong identity. Reverting stops future effects but does not automatically undo instances or records already created.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant