Skip to content

[mesheryctl-axi] Require HTTPS for non-loopback endpoints before sending auth cookies - #90

Merged
ritzorama merged 5 commits into
meshery-extensions:masterfrom
RameshwariS:fix/endpoint_security
Nov 17, 2026
Merged

ritzorama merged 5 commits into
meshery-extensions:masterfrom
RameshwariS:fix/endpoint_security

Conversation

@RameshwariS

@RameshwariS RameshwariS commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Notes for Reviewers

Problem

serverGetJson sent the token and meshery-provider cookies to any configured endpoint, including a plain http:// URL on a remote host. That exposes the Meshery token in cleartext on the network (CWE-319).

Change

  • src/server.ts: before the Cookie header is built, assertSecureEndpoint() checks the endpoint:
    • https://: allowed for any host (no change)
    • http:// to a loopback host (localhost, 127.0.0.0/8, ::1): allowed, so local Meshery deployments keep working
    • anything else: rejected with VALIDATION_ERROR before any request is sent
  • isLoopbackHost() matches on the parsed hostname, not a string prefix, so lookalikes such as localhost.com or 127.0.0.1.evil.com are rejected.
  • Anonymous requests (the /api/system/version probe) send no cookies and are not checked.

All authenticated API callers go through this helper, so design, model, component and connection are covered.

Behaviour change

Users whose mesheryctl context points at a remote http:// endpoint now get an error instead of a silent credential leak. They need to switch the context to https://. This should go out with the minor label.

Testing

test/server-security.test.ts (25 tests): lookalike and remote HTTP hosts are rejected and the fetcher is never called; loopback HTTP and HTTPS hosts still receive the cookie; anonymous remote HTTP requests succeed with no cookie. make build tests passes.

Manual check: connection list against a local listener bound to a LAN IP.

Before (listener receives the token):
COOKIE: token=FAKE-SECRET-TOKEN-123; meshery-provider=Meshery

After:
error: "Refusing to send Meshery credentials over cleartext http://172.20.10.3:9999"
code: VALIDATION_ERROR
help[2]:
Point the mesheryctl context at an https:// endpoint
Or use a loopback endpoint (localhost / 127.0.0.1) for a local Meshery

With http://localhost:9999 the command still succeeds.

Signed commits

  • Yes, I signed my commits.

Summary by CodeRabbit

  • Bug Fixes
    • Authenticated requests to non-loopback HTTP endpoints are now rejected before credentials are sent.
    • Authenticated requests continue to work with HTTPS endpoints and HTTP endpoints on localhost or loopback addresses.
    • Anonymous requests to HTTP endpoints remain available without sending authentication cookies.

…ing auth cookies

Signed-off-by: RameshwariS <shrutisatpute1112@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 48 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3b94b845-3db1-40e1-88e1-bb8db26caa67
Commits

Reviewing files that changed from the base of the PR and between a6e6869 and e2114d7.

Files selected for processing: 2

  • src/server.ts
  • test/server-security.test.ts

No actionable comments were generated in the recent review.

Walkthrough

Authenticated requests now validate their endpoint before serverGetJson adds auth cookies. HTTPS and loopback HTTP endpoints are accepted. Tests cover loopback host detection, authenticated requests, and anonymous requests.

Changes: Endpoint security validation

Layer / File(s) Summary
Loopback classification and endpoint policy
src/server.ts
Adds isLoopbackHost and endpoint validation. HTTPS and loopback HTTP are accepted; other endpoints are rejected.
Request enforcement and validation
src/server.ts, test/server-security.test.ts
Validates authenticated requests before adding cookies. Tests cover remote HTTP rejection, allowed endpoint cookie behavior, and anonymous remote HTTP requests.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Suggested labels: area/src, area/test, minor

Suggested reviewers: yi-nuo426, tanav29, marblom007

Merge Risk: Minimal · previous review a6e68

This change makes authenticated requests fail with a validation error when the endpoint is plain HTTP on a non-loopback host. This stops the token and provider cookies from being sent in cleartext. Loopback HTTP and HTTPS keep working. No merge-blocking risk was found, and users with remote http:// contexts will need to switch to HTTPS.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: non-loopback endpoints must use HTTPS before auth cookies are sent. The raw summary shows assertSecureEndpoint in src/server.ts and serverGetJson calling it befo…
Linked Issues check Passed [#88] requires that the shared serverGetJson helper reject non-loopback http:// endpoints before the Cookie header is built, keep loopback HTTP, and leave HTTPS unchanged. At head, src/server.ts calls…
Out of Scope Changes check Passed The whole-PR diff against the merge base consists of the endpoint check in src/server.ts (isLoopbackHost, assertSecureEndpoint, and one call site) and the new test/server-security.test.ts. The diff to…
Full details: Title check

Explanation

The title names the main change: non-loopback endpoints must use HTTPS before auth cookies are sent. The raw summary shows assertSecureEndpoint in src/server.ts and serverGetJson calling it before adding cookies. The new tests cover the same behavior. The title does not list files and is short enough for a history scan.

Full details: Linked Issues check

Explanation

[#88] requires that the shared serverGetJson helper reject non-loopback http:// endpoints before the Cookie header is built, keep loopback HTTP, and leave HTTPS unchanged. At head, src/server.ts calls assertSecureEndpoint(endpoint) inside the !options.anonymous &amp;&amp; auth branch, before the Cookie header is assigned. assertSecureEndpoint allows https: for any host, allows http: only when isLoopbackHost() is true, and otherwise throws VALIDATION_ERROR. isLoopbackHost() parses the hostname, strips IPv6 brackets, and accepts only 'localhost', IPv4 127.0.0.0/8 (via isIP), and '::1'. Lookalikes such as 'localhost.com' and '127.0.0.1.evil.com' return false. Because all authenticated callers use serverGetJson, they inherit the check. test/server-security.test.ts (25 cases by count) covers rejected remote and lookalike HTTP hosts with no fetch call, loopback HTTP and remote HTTPS cookies, and anonymous remote HTTP without cookies. I did not run the test suite. The test assertions match the code as read.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base consists of the endpoint check in src/server.ts (isLoopbackHost, assertSecureEndpoint, and one call site) and the new test/server-security.test.ts. The diff tool could not return a text diff, so the changed-file set rests on the supplied summary and the file reads at head. Each change supports #88. The only behavior beyond the issue text is rejection of non-http(s) protocols and of invalid URLs with VALIDATION_ERROR. This is a narrow extension of the same validation and does not affect unrelated commands. The anonymous version probe path is unchanged, as the issue requires.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 41f7c0f9-057d-43fe-895a-ffd61cad14e1
Commits

Reviewing files that changed from the base of the PR and between 4d45477 and a6e6869.

Files selected for processing: 2

  • src/server.ts
  • test/server-security.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@leecalcote
leecalcote requested a review from ritzorama November 17, 2026 16:37
RameshwariS and others added 4 commits November 17, 2026 22:08
Signed-off-by: RameshwariS <152020696+RameshwariS@users.noreply.github.com>
Signed-off-by: RameshwariS <shrutisatpute1112@gmail.com>
Signed-off-by: RameshwariS <shrutisatpute1112@gmail.com>
The previous inline loopback check accepted the trailing-dot root
form localhost.; the new isLoopbackHost helper dropped it. Keep
accepting it and cover it in the test list.

Signed-off-by: ritzorama <ritzorama@users.noreply.github.com>

@ritzorama ritzorama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work - this closes the credential-leak hole in #88 cleanly.

What I verified:

  • The guard is in the right place: every authenticated call goes through serverRequestJson, and the check runs before buildUrl, so a bad endpoint now gets the readable VALIDATION_ERROR instead of a TypeError.
  • Lookalike hosts (localhost.com, 127.0.0.1.evil.com) are rejected on the parsed hostname, not a string prefix - that was the subtle part, and the tests pin it down.
  • Anonymous requests still go through with no cookie, and loopback HTTP plus any HTTPS endpoint keep working.
  • Local verification on the current head: format-check, lint, tsc build, and the full suite (212 passed) are all green.

Two small fixes I pushed to the branch:

  • Import order for the repo prettier setup (you had already fixed most of it in 7debb3c).
  • Kept accepting the trailing-dot root form localhost., which the old inline check accepted - added it to the test list so it stays covered.

CI is re-running on the latest push; once it is green this is good to merge.

@ritzorama
ritzorama merged commit 51b7f88 into meshery-extensions:master Nov 17, 2026
6 checks passed
@RameshwariS

Copy link
Copy Markdown
Contributor Author

Thanks! @ritzorama

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Require HTTPS for non-loopback endpoints before sending auth cookies in serverGetJson

2 participants