fix: harden ssh local tunnel binding against TOCTOU races#215
Merged
datlechin merged 1 commit intoTableProApp:mainfrom Mar 9, 2026
Merged
fix: harden ssh local tunnel binding against TOCTOU races#215datlechin merged 1 commit intoTableProApp:mainfrom
datlechin merged 1 commit intoTableProApp:mainfrom
Conversation
Stop pre-scanning for an open local port before launching ssh. Instead, let ssh bind the forwarded port directly with `ExitOnForwardFailure=yes` and retry only when stderr shows a local bind failure. Also tighten tunnel readiness checks so the forwarded port must be reachable and owned by the launched process tree, preventing false positives if another local process grabs the port first. Add focused tests for retryable bind failures and process-tree ownership checks.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #216
Summary
Harden SSH local port forwarding against a TOCTOU race during tunnel setup.
Previously, TablePro scanned for a free local port, released it, and only then launched
ssh -L .... Another local process could bind that port in the gap between the availability check and the actualsshbind.This change removes that race by letting
sshperform the bind directly and retrying only whensshreports a local forwarding bind failure.What changed
findAvailablePort()flow with launch-and-retry logic over candidate ports-o ExitOnForwardFailure=yesso local forwarding bind failures fail fast127.0.0.1Why
The old flow had a classic TOCTOU window:
sshlater attempted to bind the same portA competing local process could win that race and either:
sshto fail binding, orThis PR makes tunnel setup fail closed and retries only on the specific local bind race case.
Testing