Skip to content

fix(ios): force tls for non-loopback manual gateway hosts#21969

Merged
mbelinky merged 1 commit intomainfrom
fix/ios-manual-tls-nonloopback
Feb 20, 2026
Merged

fix(ios): force tls for non-loopback manual gateway hosts#21969
mbelinky merged 1 commit intomainfrom
fix/ios-manual-tls-nonloopback

Conversation

@mbelinky
Copy link
Contributor

@mbelinky mbelinky commented Feb 20, 2026

Summary\n- force TLS for manual gateway hosts that are not true loopback\n- keep .ts.net default-port behavior unchanged\n- harden loopback detection to avoid prefix-bypass hosts like 127.attacker.example\n- add gateway security tests for manual TLS behavior and default port behavior\n\n## Why\nThis supersedes the iOS part of #21441 with a tighter loopback matcher and focused scope.

Greptile Summary

This PR hardens iOS manual gateway connections by forcing TLS for all non-loopback hosts. It introduces a robust isLoopbackHost check using inet_pton (preventing hostname prefix-bypass attacks like 127.attacker.example), adds resolveManualUseTLS to centralize the TLS decision, and consistently applies it across all three manual-connection code paths (connectManual, maybeAutoConnect manual branch, and maybeAutoConnect last-known branch). The existing .ts.net default-port logic (shouldForceTLS) is preserved unchanged for port resolution only.

  • All three manual gateway connection paths now force TLS for non-loopback hosts
  • Loopback detection covers IPv4 (127.0.0.0/8), IPv6 (::1), IPv4-mapped IPv6 (::ffff:127.x.x.x), localhost, 0.0.0.0, ::, bracket-wrapped addresses, and zone IDs
  • New tests verify both the TLS enforcement and default-port behavior invariants
  • shouldForceTLS (.ts.net detection) is retained solely for the resolveManualPort default-port logic

Confidence Score: 5/5

  • This PR is a well-scoped security hardening change that is safe to merge.
  • The changes are focused on a clear security improvement (forcing TLS for non-loopback manual gateway hosts). The loopback detection is implemented correctly using inet_pton for robust IP parsing, preventing hostname prefix-bypass attacks. All three manual-connection code paths are consistently updated. The existing .ts.net default-port behavior is preserved. New tests cover the key security invariants including edge cases. No logic errors or regressions detected.
  • No files require special attention.

Last reviewed commit: 7a8ccbe

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 7 to 10
import Foundation
import Darwin
import OpenClawKit
import Network
Copy link
Contributor

Choose a reason for hiding this comment

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

Import ordering nit
Darwin and the surrounding imports are not in alphabetical order — Darwin should come before EventKit/Foundation, and Network should come before OpenClawKit. The list was already slightly out of order before this PR, but adding Darwin between Foundation and OpenClawKit extends the inconsistency.

Suggested change
import Foundation
import Darwin
import OpenClawKit
import Network
import Foundation
import Darwin
import Network
import OpenClawKit

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/ios/Sources/Gateway/GatewayConnectionController.swift
Line: 7-10

Comment:
**Import ordering nit**
`Darwin` and the surrounding imports are not in alphabetical order — `Darwin` should come before `EventKit`/`Foundation`, and `Network` should come before `OpenClawKit`. The list was already slightly out of order before this PR, but adding `Darwin` between `Foundation` and `OpenClawKit` extends the inconsistency.

```suggestion
import Foundation
import Darwin
import Network
import OpenClawKit
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@mbelinky mbelinky force-pushed the fix/ios-manual-tls-nonloopback branch from 7a8ccbe to 9fb39f5 Compare February 20, 2026 16:10
@openclaw-barnacle openclaw-barnacle bot added the docs Improvements or additions to documentation label Feb 20, 2026
@bmendonca3
Copy link

Thanks for keeping scope tight and adding the regression tests

@mbelinky mbelinky merged commit 8fa46d7 into main Feb 20, 2026
20 of 21 checks passed
@mbelinky mbelinky deleted the fix/ios-manual-tls-nonloopback branch February 20, 2026 16:28
@mbelinky
Copy link
Contributor Author

Merged via squash.

Thanks @mbelinky!

rodrigogs pushed a commit to rodrigogs/openclaw that referenced this pull request Feb 20, 2026
…1969)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 9fb39f5
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
Hansen1018 added a commit to Hansen1018/openclaw that referenced this pull request Feb 21, 2026
…1969)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 9fb39f5
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
vincentkoc pushed a commit that referenced this pull request Feb 21, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 9fb39f5
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
dgarson pushed a commit to dgarson/clawdbot that referenced this pull request Feb 21, 2026
…1969)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 9fb39f5
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
mmyyfirstb pushed a commit to mmyyfirstb/openclaw that referenced this pull request Feb 21, 2026
…1969)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 9fb39f5
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
obviyus pushed a commit to guirguispierre/openclaw that referenced this pull request Feb 22, 2026
…1969)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 9fb39f5
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
mreedr pushed a commit to mreedr/openclaw-custom that referenced this pull request Feb 24, 2026
…1969)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 9fb39f5
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
…1969)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 9fb39f5
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky

(cherry picked from commit 8fa46d7)

# Conflicts:
#	apps/ios/Sources/Gateway/GatewayConnectionController.swift
#	apps/ios/Tests/GatewayConnectionSecurityTests.swift
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
…1969)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 9fb39f5
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky

(cherry picked from commit 8fa46d7)

# Conflicts:
#	apps/ios/Sources/Gateway/GatewayConnectionController.swift
#	apps/ios/Tests/GatewayConnectionSecurityTests.swift
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…1969)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 9fb39f5
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: ios App: ios docs Improvements or additions to documentation maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants