Repository navigation
fix: harden auth, SSH, plugin, Electron, database, and Docker security - #1998
Open
ZacharyZcR wants to merge 1 commit into
Open
ZacharyZcR wants to merge 1 commit into
ZacharyZcR wants to merge 1 commit into
Conversation
|
AI review | Looks safe to merge This PR hardens authentication, SSH connections, plugin runtime, Electron IPC, database operations, and Docker builds against multiple security and stability issues. It fixes real vulnerabilities including 2FA token replay, path traversal, PID reuse attacks, SSRF bypasses, and connection pool collisions, while addressing concurrency races and resource leaks without introducing any malicious code or rule violations. Reviewed 475b193. AI can be wrong, a maintainer still decides. Comment |
This branch has not been deployed
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.
Summary
This PR addresses a set of security, concurrency, and stability issues across authentication, SSH/credentials, plugin runtime/SDK, Electron/frontend, database repositories, and Docker/build scripts.
Authentication & Access Control
temp_tokenreplay & policy bypass (src/backend/auth/login-pipeline.ts): RejectreadPendingLogin()when no matching in-memory pending login exists instead of falling back topending: null, and atomically consume pending logins upon verification.src/backend/auth/step-up.ts,src/backend/database/routes/step-up-routes.ts,src/backend/utils/auth-manager.ts): Scope step-up verification tosessionIdwith TTL cleanup, clear onlogoutUser(), normalize auth paths (session-access.ts,auth-manager.ts) to prevent case/encoding bypasses, touch sessions increateAdminMiddleware(), and propagatesessionRepository.create()errors ingenerateJWTToken().X-Forwarded-Prefix(src/backend/utils/request-origin.ts): Reject protocol-relative (//...) and backslash-containing base paths innormalizeBasePath().src/backend/utils/safe-outbound-fetch.ts): Fix unescaped character class/^[|]$/gto/^\[|\]$/g.NaN(src/backend/database/routes/audit-log-routes.ts).SSH, Credentials & Operations
socks5ProxyChainpasswords end-to-end (src/backend/utils/field-crypto.ts,src/backend/utils/lazy-field-encryption.ts,src/backend/database/routes/host-normalizers.ts,src/backend/hosts/import/host-export.ts,src/backend/hosts/credential-storage.ts): Encrypt proxy chain field at rest, strip nested passwords from API responses, shared exports, and credential-storage-disabled writes.src/backend/hosts/connect/connect-host.ts): Key connections by acting user plussocks5ProxyChain,jumpHosts,authType, andcredentialId, and clean up timer/jump client on synchronousconnect()errors.src/backend/hosts/ssh-relay.ts,src/backend/hosts/jump-host-chain.ts,src/backend/hosts/host-key-verifier.ts): FixMAX_RELAYS_PER_USERTOCTOU and disconnect-before-connect socket/jumpClient leak; destroy unboundproxySocketand lateforwardOutstreams; handle WebSocketcloseand DB errors cleanly in host-key verification.src/backend/database/repositories/host-repository.ts): CheckfindByIdForUser()before callingdeleteAccessForHost().src/backend/operations/gate.ts,src/backend/operations/resources.ts): Check API key scopes againsteffectiveRisk, enforce admin/registration checks indecideOperationApproval(), redactundoInput, include serialized input in resource cache keys, and align defaulthostAccesswithgate.ts.src/backend/database/database.ts): Use realvalidateJWTSecret()instead of hardcodedtrue, and ensure temporary export SQLite files are removed if opening/initializing fails.Plugin Runtime & SDK
ctx.asUser(src/backend/plugins/ctx.ts): RequireassertCapability(..., "users:impersonate")instead of manifest-only check.packages/plugin-sdk/src/ddl.ts): Check refused functions andsetvalacross all DML statements (INSERT/REPLACE/UPDATE/DELETE, not onlySELECT), and unwrap quoted identifiers so"pg_read_file"(...)cannot bypass checks.src/backend/plugins/ctx-process.ts,ctx-audit.ts,ctx-desktop-local.ts): Block./..binary names, enforce download size limit and cancel redirected response bodies, guard async audit subscriptions against disposal race, and block#/encoded traversal inpluginFetch.Electron & Frontend
create-temp-folderIPC (electron/main.cjs): Reject./..path segments and verify resolved target paths stay within the temp folder.isPrivateNetworkHostfalse positives onfc*/fd*domains (electron/main.cjs): Strip IPv6 brackets and require:before matchingfc/fdULA prefixes.electron/backend-process.cjs,electron/main.cjs): Verify the recorded PID belongs to a Termix backend process before killing it.127.0.0.1& case-insensitiveSameSiteheader check (electron/main.cjs).http:/https:only) (src/ui/plugins/plugin-model.ts,PluginDetail.tsx,PluginReleaseNotes.tsx).currentUseron logout & clean up drag listeners (src/ui/plugin-host/bridge.ts,loader.ts,src/ui/shell/controller/use-regions.ts,CompanionFrame.tsx,CardGridCanvas.tsx).Database, Docker & Build Scripts
src/backend/database/repositories/user-repository.ts,plugin-settings-repository.ts): Add.limit(1)and PG/MySQL locking increateCheckingIfFirst(), and wrapPluginSettingsRepository.set()in a transaction with lock/deduplication forscope_id IS NULL.SUBSTR, and transactions (src/backend/database/repositories/host-folder-repository.ts,folder-access-repository.ts).src/backend/database/db/connect.ts,index.ts,src/backend/starter.ts): Close PG/MySQL pools on shutdown and wrap table rebuilds in transactions that restorePRAGMA foreign_keys = ONinfinally.docker/Dockerfile,docker/entrypoint.sh): Build only frontend assets into/app/html(no longer exposingdist/backendordist/pluginsvia Nginx), applypatch-ssh2-sk.cjsin Docker builds, remove redundantnpm rebuild bcryptjs, include Nginx inHEALTHCHECK, parseDATA_DIR/.envsafely withoutsource, and respectSSL_CERT_PATH/SSL_KEY_PATH.postinstallpatches & align V8 macro (scripts/patch-app-builder-lib.cjs,patch-better-sqlite3.cjs,patch-nan.cjs,patch-node-pty.cjs).Verification
npm run type-check: passednpm run lint: passed (0 errors)npm run test: verified across backend, frontend, and scripts test suites (including added regression tests indata.test.ts,capabilities.test.ts,actor.test.ts, andssh-relay.test.ts)