Skip to content

fix(auth): hide instance token when exposure disabled - #2736

Open
aim1sh wants to merge 1 commit into
evolution-foundation:developfrom
aim1sh:fix/hide-instance-token
Open

aim1sh wants to merge 1 commit into
evolution-foundation:developfrom
aim1sh:fix/hide-instance-token

Conversation

@aim1sh

@aim1sh aim1sh commented Sep 22, 2026 •

Copy link
Copy Markdown

📋 Description

Prevent GET /instance/fetchInstances from returning instance tokens when AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=false.

The response is sanitized consistently for:

  • lookups authenticated with an instance token
  • lookups by instance ID or number
  • unfiltered and name-filtered instance listings

When exposure is explicitly enabled, the existing response remains unchanged.

🔗 Related Issue

Closes #2677

🧪 Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • 🔒 Security fix

🧪 Testing

  • No breaking changes introduced
  • npx eslint src/api/controllers/instance.controller.ts
  • npx tsc --noEmit
  • npm run build

✅ Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • My changes generate no new warnings

📝 Additional Notes

The change only removes the token property from returned copies of instance records; it does not mutate the records returned by the monitoring service.

Summary by Sourcery

Hide instance tokens from fetch responses unless token exposure is explicitly enabled.

Bug Fixes:

  • Prevent instance tokens from being returned by the instance listing endpoint when token exposure is disabled.

Enhancements:

  • Apply consistent token redaction across token-authenticated, ID/number-based, and filtered or unfiltered instance lookups while preserving existing responses when exposure is enabled.

Remove instance tokens from fetchInstances responses unless AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES is explicitly enabled.
@sourcery-ai

sourcery-ai Bot commented Sep 22, 2026 •

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

Reviewer's Guide

Updates instance fetching to hide instance tokens whenever AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES is disabled, while preserving the existing response when explicitly enabled and avoiding mutation of source records.

Sequence diagram for sanitized instance fetching

sequenceDiagram
    participant Client
    participant InstanceController
    participant PrismaRepository
    participant WAMonitor

    Client->>InstanceController: fetchInstances(instanceName, instanceId, number, key)
    InstanceController->>InstanceController: get AUTHENTICATION settings
    alt Invalid API key
        InstanceController->>PrismaRepository: findMany(instance names)
        PrismaRepository-->>InstanceController: authorized instances
        InstanceController->>WAMonitor: instanceInfo(names)
        WAMonitor-->>InstanceController: instance records
    else Lookup by instanceId or number
        InstanceController->>WAMonitor: instanceInfoById(instanceId, number)
        WAMonitor-->>InstanceController: instance records
    else Unfiltered or name-filtered lookup
        InstanceController->>WAMonitor: instanceInfo(instanceNames)
        WAMonitor-->>InstanceController: instance records
    end
    alt EXPOSE_IN_FETCH_INSTANCES enabled
        InstanceController-->>Client: records including token
    else Exposure disabled
        InstanceController->>InstanceController: hideTokens(instances)
        InstanceController-->>Client: copied records without token
    end
Loading

File-Level Changes

Change Details Files
Sanitize instance lookup responses by conditionally removing tokens without mutating monitoring-service records.
  • Read the authentication exposure setting.
  • Add a copy-based token-removal helper that preserves responses when exposure is enabled.
  • Apply sanitization to token-authenticated, ID/number-based, unfiltered, and name-filtered lookups.
src/api/controllers/instance.controller.ts

Possibly linked issues


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 whether authenticated callers receive instance tokens, which are credentials and could affect access to instances. Reverting restores the previous response behavior, but any tokens exposed during an incorrect configuration or implementation could be used before the revert.


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