Skip to content

fix(security): prevent unauthenticated disclosure of instance metadata [APP-14994] - #41598

Merged
subrata71 merged 5 commits into
releasefrom
feat/APP-14994
Mar 16, 2026
Merged

subrata71 merged 5 commits into
releasefrom
feat/APP-14994

Conversation

@subrata71

@subrata71 subrata71 commented Mar 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes APP-14994: three API endpoints were accessible without authentication and exposed sensitive instance metadata to any unauthenticated caller.

  • /api/v1/users/features — removed from permitAll() in SecurityConfig; now returns 401 for unauthenticated requests. Feature flags are per-user data and must not be disclosed to anonymous callers.
  • /api/v1/tenants/current — kept accessible without authentication (the login page uses it to discover enabled auth providers), but instanceId and adminEmailDomainHash are now suppressed from the response when the caller is anonymous. This eliminates exposure of the unsalted SHA-256 admin-email-domain hash and the instance UUID.
  • /api/v1/consolidated-api/view — kept accessible without authentication (required for public/published apps), but the embedded organizationConfig no longer contains instanceId or adminEmailDomainHash for anonymous callers (same service-layer fix as above).

Changes

File Change
SecurityConfig.java Remove GET /api/v1/users/features from permitAll()
OrganizationServiceCEImpl.java Check ReactiveSecurityContextHolder in getOrganizationConfiguration(); skip setting instanceId / adminEmailDomainHash for anonymous principals
OrganizationServiceCETest.java Add two tests: anonymous caller gets null for sensitive fields; authenticated caller gets non-null values
AuthGuardTest.java New controller-level test: GET /api/v1/users/features returns 401 for unauthenticated requests; GET /api/v1/tenants/current remains accessible

Test plan

  • OrganizationServiceCETest#getOrganizationConfig_AnonymousUser_DoesNotExposeInstanceMetadata — asserts instanceId and adminEmailDomainHash are null for anonymous callers
  • OrganizationServiceCETest#getOrganizationConfig_AuthenticatedUser_ExposesInstanceMetadata — asserts both fields are non-null for authenticated callers
  • AuthGuardTest#featureFlagsEndpoint_unauthenticated_returns401 — HTTP 401 for unauthenticated GET /api/v1/users/features
  • AuthGuardTest#tenantCurrentEndpoint_unauthenticated_isAccessible — GET /api/v1/tenants/current still returns 200 without auth
  • All 15 existing OrganizationServiceCETest tests pass (1 pre-existing disabled test skipped)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • The user features endpoint now requires authentication.
    • Organization instance metadata (instanceId, adminEmailDomainHash) is concealed for unauthenticated requests; tenant/current remains accessible but without sensitive fields.
  • Tests

    • Added tests validating authentication for the features endpoint and that anonymous vs. authenticated users receive appropriately filtered organization metadata.

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/22959284307
Commit: 1bcf565
Cypress dashboard.
Tags: @tag.All
Spec:


Wed, 11 Mar 2026 16:17:45 UTC

…a [APP-14994]

Three API endpoints were accessible without authentication and leaked
sensitive instance metadata to any caller:

- /api/v1/users/features – removed from permitAll(); now requires an
  authenticated session. Feature flags are per-user data and must not
  be disclosed to anonymous callers.

- /api/v1/tenants/current and /api/v1/consolidated-api/view – kept
  accessible without authentication (login page and public apps depend
  on them) but instanceId and adminEmailDomainHash are now suppressed
  from the response when the caller is anonymous. This eliminates
  disclosure of the unsalted SHA-256 admin-email-domain hash and the
  instance UUID while preserving the auth-provider discovery needed by
  the login page.

Tests added: AuthGuardTest (controller-level 401 for /users/features)
and two new cases in OrganizationServiceCETest that assert anonymous
callers receive null instanceId/adminEmailDomainHash while
authenticated callers still receive both fields.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@linear

linear Bot commented Mar 9, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Removed public GET access to /api/v1/users/features and updated organization config logic to hide instanceId and adminEmailDomainHash for anonymous users while exposing them to authenticated users.

Changes

Cohort / File(s) Summary
Security Configuration
app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/SecurityConfig.java
Removed unauthenticated GET matcher for USER_URL + "/features", making the features endpoint require authentication.
Organization Service Logic
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/OrganizationServiceCEImpl.java
Added reactive security context check to detect anonymous principal and conditionally omit instanceId and adminEmailDomainHash from organization responses for anonymous users.
Integration Tests
app/server/appsmith-server/src/test/java/com/appsmith/server/configurations/AuthGuardTest.java
New tests: assert /api/v1/users/features returns 401 for unauthenticated requests; assert /api/v1/tenants/current returns 200 but omits sensitive fields for anonymous requests.
Service Unit Tests
app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/OrganizationServiceCETest.java
Added tests verifying organization metadata is null for anonymous users and present for authenticated users.

Sequence Diagram

sequenceDiagram
    participant Client
    participant SecurityContext as Security Context
    participant OrgService as Organization Service
    participant Response as Data Response

    alt Authenticated User Request
        Client->>SecurityContext: GET /api/v1/tenants/current
        SecurityContext->>OrgService: authenticated principal
        OrgService->>Response: include instanceId & adminEmailDomainHash
        Response-->>Client: 200 OK (full metadata)
    else Anonymous User Request
        Client->>SecurityContext: GET /api/v1/tenants/current
        SecurityContext->>OrgService: anonymous principal
        OrgService->>Response: nullify instanceId & adminEmailDomainHash
        Response-->>Client: 200 OK (sanitized)
    else Unauthenticated to Protected Endpoint
        Client->>SecurityContext: GET /api/v1/users/features
        SecurityContext-->>Client: 401 Unauthorized
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🔐 A feature gate now needs a key,
Anonymous eyes no longer see,
Instance whispers tucked away,
Authenticated minds may say,
Safer dawn for metadata today ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main security fix: preventing unauthenticated disclosure of instance metadata, with the issue reference APP-14994.
Description check ✅ Passed PR description comprehensively covers all changes, includes issue reference, test plan, and Cypress results validation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/APP-14994

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/OrganizationServiceCEImpl.java (1)

164-167: Guard the principal cast before using it as a User.

defaultIfEmpty(true) only helps when the security context is absent. In WebFlux security, an anonymous request can still carry an Authentication whose default principal is anonymousUser, so this direct cast can fail before the anonymous fallback runs. Please gate the cast with instanceof User and then use User.isAnonymous(). (docs.spring.vmware.com)

Suggested hardening
-        Mono<Boolean> isAnonymousMono = ReactiveSecurityContextHolder.getContext()
-                .map(ctx -> (User) ctx.getAuthentication().getPrincipal())
-                .map(user -> Boolean.TRUE.equals(user.getIsAnonymous()))
-                .defaultIfEmpty(true);
+        Mono<Boolean> isAnonymousMono = ReactiveSecurityContextHolder.getContext()
+                .flatMap(ctx -> Mono.justOrEmpty(ctx.getAuthentication()))
+                .filter(authentication -> authentication.getPrincipal() instanceof User)
+                .map(authentication -> ((User) authentication.getPrincipal()).isAnonymous())
+                .defaultIfEmpty(true);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/OrganizationServiceCEImpl.java`
around lines 164 - 167, In OrganizationServiceCEImpl, the mapping from
ReactiveSecurityContextHolder currently casts the principal to User directly;
change the map chain to first check that ctx.getAuthentication() and
ctx.getAuthentication().getPrincipal() are present and that principal instanceof
User before casting, and then call ((User) principal).getIsAnonymous() (or
User.isAnonymous()) to produce the boolean; keep defaultIfEmpty(true) to cover
missing context but avoid a ClassCastException by gating the cast with an
instanceof check in the mapping function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@app/server/appsmith-server/src/test/java/com/appsmith/server/configurations/AuthGuardTest.java`:
- Around line 48-55: Update the test method
tenantCurrentEndpoint_unauthenticated_isAccessible in AuthGuardTest to assert
the response body nulls for sensitive fields: after the existing
.expectStatus().isOk(), add a body assertion using webTestClient's
.expectBody()/.jsonPath() to verify "$.instanceId" and "$.adminEmailDomainHash"
are null (e.g., .jsonPath("$.instanceId").isEqualTo(null) and
.jsonPath("$.adminEmailDomainHash").isEqualTo(null)). Keep the existing call
chain and only append these jsonPath assertions to confirm unauthenticated
responses suppress those fields.

---

Nitpick comments:
In
`@app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/OrganizationServiceCEImpl.java`:
- Around line 164-167: In OrganizationServiceCEImpl, the mapping from
ReactiveSecurityContextHolder currently casts the principal to User directly;
change the map chain to first check that ctx.getAuthentication() and
ctx.getAuthentication().getPrincipal() are present and that principal instanceof
User before casting, and then call ((User) principal).getIsAnonymous() (or
User.isAnonymous()) to produce the boolean; keep defaultIfEmpty(true) to cover
missing context but avoid a ClassCastException by gating the cast with an
instanceof check in the mapping function.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 735ed917-b65b-46e5-b764-1ea68153c551

📥 Commits

Reviewing files that changed from the base of the PR and between 13313df and 93ad1a2.

📒 Files selected for processing (4)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/SecurityConfig.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/OrganizationServiceCEImpl.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/configurations/AuthGuardTest.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/OrganizationServiceCETest.java
💤 Files with no reviewable changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/SecurityConfig.java

- Guard principal cast with instanceof User before casting in
  OrganizationServiceCEImpl to avoid ClassCastException when the
  security context holds a non-User anonymous principal
- Extend AuthGuardTest to assert that instanceId and adminEmailDomainHash
  are absent from the /api/v1/tenants/current response for unauthenticated
  callers, not just that the endpoint returns 200

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/OrganizationServiceCEImpl.java (1)

162-178: Solid implementation with correct defensive guards.

The instanceof User filter before casting correctly handles Spring Security's AnonymousAuthenticationToken (which holds a String principal, not User). The defaultIfEmpty(true) ensures missing security context (e.g., internal service calls) safely defaults to anonymous behavior.

Minor observation: User has a null-safe isAnonymous() method that returns boolean, whereas getIsAnonymous() returns the nullable Boolean field. Since the field defaults to false, this works, but using isAnonymous() would be marginally safer.

,

Optional: use null-safe method
         .filter(authentication -> authentication.getPrincipal() instanceof User)
-        .map(authentication -> ((User) authentication.getPrincipal()).getIsAnonymous())
+        .map(authentication -> ((User) authentication.getPrincipal()).isAnonymous())
         .defaultIfEmpty(true);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/OrganizationServiceCEImpl.java`
around lines 162 - 178, Use the null-safe boolean accessor on User: change the
mapping inside isAnonymousMono from .map(authentication -> ((User)
authentication.getPrincipal()).getIsAnonymous()) to call the primitive-returning
method .map(authentication -> ((User)
authentication.getPrincipal()).isAnonymous()), so isAnonymousMono uses
User.isAnonymous() (located in the ReactiveSecurityContextHolder ->
isAnonymousMono construction) to avoid nullable Boolean handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/OrganizationServiceCEImpl.java`:
- Around line 162-178: Use the null-safe boolean accessor on User: change the
mapping inside isAnonymousMono from .map(authentication -> ((User)
authentication.getPrincipal()).getIsAnonymous()) to call the primitive-returning
method .map(authentication -> ((User)
authentication.getPrincipal()).isAnonymous()), so isAnonymousMono uses
User.isAnonymous() (located in the ReactiveSecurityContextHolder ->
isAnonymousMono construction) to avoid nullable Boolean handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9a04048f-4bfb-4e7a-8228-e917a656c7cf

📥 Commits

Reviewing files that changed from the base of the PR and between 93ad1a2 and 77141a9.

📒 Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/OrganizationServiceCEImpl.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/configurations/AuthGuardTest.java

@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown

Failed server tests

  • com.appsmith.server.git.ops.GitConnectTests#connectArtifactToGit_whenUsingGlobalProfile_completesSuccessfully

@subrata71 subrata71 self-assigned this Mar 10, 2026
@subrata71 subrata71 added the ok-to-test Required label for CI label Mar 10, 2026
@subrata71
subrata71 requested a review from sondermanish March 10, 2026 10:26
ServerWebExchangeMatchers.pathMatchers(HttpMethod.PUT, USER_URL + "/invite/confirm"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, USER_URL + "/me"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/v3/**"),
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, USER_URL + "/features"),

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.

qq: why was it present here? did we have any usecase for this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The endpoint was originally added to permitAll() so the client could fetch feature flags before authentication — for example, to enable/disable UI features on the login page itself. However, this also lets any unauthenticated caller enumerate which paid/enterprise features are enabled on the instance, which is the information-disclosure issue in APP-14994. Since the login page doesn't actually depend on these flags pre-auth, removing it from permitAll() is safe.

.defaultIfEmpty(true);

Mono<Organization> clientOrganizationMono = isAnonymousMono.flatMap(
isAnonymous -> configService.getInstanceId().flatMap(instanceId -> {

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.

Nit pick: for readability let's zip them together?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 47eb6e3 — switched to Mono.zip(isAnonymousMono, configService.getInstanceId()).flatMap(tuple -> { ... }) so both monos resolve concurrently and the lambda is flat. Also took the opportunity to apply the CodeRabbit nitpick: replaced getIsAnonymous() (nullable Boolean) with the null-safe isAnonymous() (boolean) method on User.

sondermanish
sondermanish previously approved these changes Mar 11, 2026
…4994]

- Use null-safe boolean User#isAnonymous() instead of getIsAnonymous()
- Zip isAnonymousMono and configService.getInstanceId() together for
  readability instead of nesting flatMap inside flatMap

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@subrata71
subrata71 merged commit 470aa9e into release Mar 16, 2026
79 checks passed
@subrata71
subrata71 deleted the feat/APP-14994 branch March 16, 2026 10:32
subrata71 added a commit that referenced this pull request Jul 16, 2026
…us users [APP-15344] (#42001)

## Summary

Fixes [APP-15344](https://linear.app/appsmith/issue/APP-15344): the
unauthenticated `/api/v1/tenants/current` endpoint was returning
internal configuration fields (Google Maps API key, license details,
migration status, feature flags) to anonymous callers.

This is the **CE portion** of the fix. The EE superset PR is
[appsmith-ee#9305](appsmithorg/appsmith-ee#9305)
(all server tests passing).

**Approach:** Service-layer filtering strips post-login-only fields when
the current user is anonymous, following the same pattern as APP-14994
(PR #41598). Only fields required by the login/signup page are preserved
(branding, auth method flags, instance name, third-party auth list).
Authenticated users receive the full unmodified response.

**CE fields stripped for anonymous users:**
- `googleMapsKey` (plaintext API key)
- Full `license` envelope (replaced with minimal `{plan: FREE}`)
- `isSignupDisabled`, `emailVerificationEnabled`,
`isStrongPasswordPolicyEnabled`
- `isAtomicPushAllowed`, `featuresWithPendingMigration`,
`migrationStatus`
- `pricingPlan` (Organization-level)

**Changes:**
1. `OrganizationConfigurationCE.stripFieldsForAnonymousUser()` — strips
CE config fields
2. `OrganizationServiceCEImpl.suppressFieldsForAnonymousUser()` — checks
security context, calls strip if anonymous
3. `OrganizationServiceCEImpl.stripOrganizationFieldsForAnonymousUser()`
— strips Organization-level fields (overridable by EE)

## Test Plan

- [x] `getOrganizationConfig_AnonymousUser_StripsInternalConfiguration`
— verifies sensitive fields are null
- [x] `getOrganizationConfig_AnonymousUser_PreservesLoginPageFields` —
verifies login-page fields remain
- [x] `getOrganizationConfig_AuthenticatedUser_ExposesFullConfiguration`
— no regression for authenticated users
- [ ] Existing APP-14994 tests pass (instanceId/adminEmailDomainHash
stripping)

/ok-to-test tags="@tag.All"


<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/29452470909>
> Commit: 151a92e
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=29452470909&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 15 Jul 2026 22:42:14 UTC
<!-- end of auto-generated comment: Cypress test results  -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Security**
* Anonymous users now receive only minimal organization configuration
and license details.
* Sensitive settings, pricing information, and privilege-related fields
are hidden from unauthenticated access.
* **Bug Fixes**
* Authenticated users continue to receive complete organization
configuration details, including updated settings.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
DhiyaneshGeek pushed a commit to projectdiscovery/nuclei-templates that referenced this pull request Nov 5, 2026
…98) (#17645)

The template matched any Appsmith instance because /api/v1/tenants/current
and /api/v1/consolidated-api/view intentionally stay reachable without
authentication (the login page uses them) and still return a 200 JSON
body after the fix. The fix in appsmithorg/appsmith#41598 (shipped in
v1.98) instead:

- removes instanceId and adminEmailDomainHash from those two responses
  for anonymous callers
- makes /api/v1/users/features return 401 for anonymous callers

Split the request so that the first two endpoints only match when one of
the removed fields is present, and /api/v1/users/features only matches
on an unauthenticated 200.

Verified: no match against a patched v1.99 instance (previously matched
on 2 URLs); matches against responses in the pre-fix shape.

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants