You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(api): every refused exec join counts against its network's budget (closes #546) - #555
The exec WebSocket's upgrade limiter counted only the joins refused at the sign-in: wrong origin, no cookie, or a session that does not authenticate. A signed-in browser could ask for a well-formed but unknown session id again and again, or for one already joined or one it may not use. Each request then answered 404 after reading and touching its sign-in, and never used the budget.
Every refused join counts against the network's budget, the 404s after the sign-in included: an unknown session, a session joined already, another person's session, no container.exec, or a join overtaken by another one. The answers stay the same uniform 404.
A join being checked counts too.admit takes a place in the budget before the sign-in lookup, and release gives it back when the check ends. Twenty concurrent joins from one network therefore use the budget up while they are checked, instead of all passing the throttled check before the first refusal is recorded.
Past 20 in a minute, a network gets 429 before any lookup, until that minute is over. A join that succeeds costs nothing, so reconnects and normal joins are unaffected unless that network also had 20 refusals in the minute.
The limiter state stays bounded. The map of refusals is pruned past 10,000 entries, as before. The new map holds only joins under way, removed when they end. Both are keyed by the client the trusted proxy forwarded (upgradeClientIp, TRUST_PROXY), as before.
SPEC 3.1 describes the budget.
How it was tested
exec-socket.spec.ts, which runs a real HTTP server and ws clients, with a counter of sign-in lookups:
Repeated unknown-id joins with a valid sign-in: 20 answer 404 with 20 lookups. The 21st, and a join of the person's own session, answer 429 with no new lookup. Once the minute is over (Date.now moved by 61 s), the own session joins again.
The other refusals count too: a session already joined, another person's session, and no permission. Each is refused 20 times with 404, then answers 429.
Refusals within the budget: 19 refusals still let a normal join through.
Concurrent joins: 25 joins while the sign-in is slow make exactly 20 lookups, the other 5 answer 429 at once, and the 20 end in 404. After that, the next join answers 429 with no lookup.
Existing tests: the limit on failed sign-ins and the trusted-proxy keying still pass unchanged.
Mutations: counting no 404s fails 3 tests, and ignoring joins under way fails the concurrency test.
Locally: API unit 999/999; lint, typecheck and format are clean.
Security considerations
Resource hardening only: no change to who may join a session or to what a refusal says.
The budget applies per network, so browsers behind one NAT share it. They are refused only after 20 refused joins in a minute, never because of successful ones.
Summary by CodeRabbit
Bug Fixes
WebSocket join requests are now rate-limited across all refused attempts, including invalid, unknown, already-joined, or unauthorized sessions. Checks still in progress also count toward the limit.
After 20 attempts per client within a minute, further requests receive a 429 response before authentication is checked. The limit resets after 60 seconds.
Documentation
Updated the WebSocket join-rate-limit description to reflect the expanded counting rules.
…closes#546)
The exec WebSocket counted only the joins refused at the sign-in. A signed-in browser could ask again and again for a session it cannot join, unknown, joined already or forbidden, and each request still read and touched its sign-in, without ever using the budget.
Every refused join now counts, 404 included, and so does each join still being checked: concurrent joins cannot all pass the check before the first refusal is recorded. Past 20 in a minute, a network gets 429 before any sign-in lookup, until the minute is over. A join that succeeds costs nothing. The joins under way are kept only while they run, next to the existing bounded map of refusals, and both are keyed by the client the trusted proxy forwarded.
Signed-off-by: samuel mbabhazi <[email protected]>
Reviewing files that changed from the base of the PR and between 71814f0 and dbd5d0e.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The WebSocket join limit now counts refused joins and joins undergoing checks. Over-limit requests receive 429 before sign-in lookup. Tests cover refusal cases, expiry, valid joins, and concurrent attempts.
Changes: Exec WebSocket join admission
Layer / File(s)
Summary
Admission, refusal handling, and validation apps/api/src/modules/deployments/interface/exec-socket.ts, apps/api/src/modules/deployments/interface/exec-socket.spec.ts, docs/SPEC.md
The upgrade path reserves a slot before checking a join and releases it after the check. Authentication, unknown-session, unjoinable-session, and access-denied refusals count toward the per-network limit. Tests cover the refusal cases, limit expiry, valid joins, and concurrent attempts. The specification describes the updated limit.
sequenceDiagram
participant Client
participant Upgrade as Exec WebSocket upgrade path
participant Admission as Per-network admission
participant SignIn as Sign-in lookup
participant JoinCheck as Session and access checks
Client->>Upgrade: Request a WebSocket join
Upgrade->>Admission: Reserve a slot
Admission-->>Upgrade: Allow or deny admission
Upgrade->>SignIn: Read sign-in after admission
Upgrade->>JoinCheck: Check session and access
JoinCheck-->>Upgrade: Return join result
Upgrade->>Admission: Release the in-progress slot
shipkeepdev/shipkeep#457: This PR changes the limiter behavior in the WebSocket upgrade path introduced by that PR.
Merge Risk: Minimal · previous review 71814
This change makes refused and in-progress WebSocket joins count against the per-client budget, so over-limit requests get 429 before sign-in lookup. No merge-blocking risk remains. The change is tested and easy to revert.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: refused exec WebSocket joins now count against the network's per-network join budget, which matches the summarized changes to exec-socket.ts, its spec, and SPEC.md. Th…
Linked Issues check
Directly linked issue #546 requires an effective admission budget for exec WebSocket upgrade refusals, including refusals after sign-in. The reviewed head implements this in exec-socket.ts. (1) `upgra…
Out of Scope Changes check
All changed files relate to #546. exec-socket.ts holds the budget logic: admission, release, refusal counting and the bounded state. exec-socket.spec.ts holds tests for those behaviors, including a si…
Full details: Title check
Explanation
The title names the main change: refused exec WebSocket joins now count against the network's per-network join budget, which matches the summarized changes to exec-socket.ts, its spec, and SPEC.md. The 'fix(api):' prefix and the issue reference are conventional and do not reduce relevance. The title is slightly long at 83 characters but remains specific and readable.
Full details: Linked Issues check
Explanation
Directly linked issue #546 requires an effective admission budget for exec WebSocket upgrade refusals, including refusals after sign-in. The reviewed head implements this in exec-socket.ts. (1) upgrade calls admit(ip) before join. admit counts recent refusals plus joins under way, and answers 429 before any sign-in lookup when the sum reaches FAILED_JOINS_PER_MINUTE (20). (2) join calls failed(ip) on every refusal: 401 from the origin, cookie or sign-in check, and 404 for unknown, already-joined, unauthorized (container.exec check) or overtaken sessions. This covers the post-authentication refusals the issue names. (3) release(ip) runs in a finally, so the in-progress reservation ends on success, refusal or error. (4) The budget window is 60 seconds, so use resumes after expiry. Successful joins do not call failed, so normal joins and reconnects are not charged. (5) failures is still pruned past 10,000 entries, and checking holds only joins under way. Both use upgradeClientIp with the existing TRUST_PROXY policy. Acceptance tests are described in the PR and raw summary (exec-socket.spec.ts: repeated unknown-ID refusals, 61-second expiry, concurrent joins, unauthorized and already-joined refusals, retained failed-sign-in and trusted-proxy tests). I did not read the spec file itself; this verdict relies on the implementation and the summarized test coverage. The objective is met by the code at head.
Full details: Out of Scope Changes check
Explanation
All changed files relate to #546. exec-socket.ts holds the budget logic: admission, release, refusal counting and the bounded state. exec-socket.spec.ts holds tests for those behaviors, including a sign-in lookup counter. docs/SPEC.md (SPEC 3.1) documents the new 429 rule, a one-line change. No unrelated behavior change appears in the reviewed code. Unchanged semantics: the uniform 404 bodies, the trusted-proxy keying and the failed-sign-in limit. The ws upgrade and join flow is otherwise untouched.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
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.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
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
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 #546.
The exec WebSocket's upgrade limiter counted only the joins refused at the sign-in: wrong origin, no cookie, or a session that does not authenticate. A signed-in browser could ask for a well-formed but unknown session id again and again, or for one already joined or one it may not use. Each request then answered 404 after reading and touching its sign-in, and never used the budget.
What changed
apps/api/src/modules/deployments/interface/exec-socket.ts:container.exec, or a join overtaken by another one. The answers stay the same uniform 404.admittakes a place in the budget before the sign-in lookup, andreleasegives it back when the check ends. Twenty concurrent joins from one network therefore use the budget up while they are checked, instead of all passing thethrottledcheck before the first refusal is recorded.upgradeClientIp,TRUST_PROXY), as before.How it was tested
exec-socket.spec.ts, which runs a real HTTP server andwsclients, with a counter of sign-in lookups:Date.nowmoved by 61 s), the own session joins again.Security considerations
Summary by CodeRabbit