Repository navigation
fix(sdk): generate server password so serve starts without configuration - #166
Open
cyb3rAcad3my wants to merge 1 commit into
Open
cyb3rAcad3my wants to merge 1 commit into
cyb3rAcad3my wants to merge 1 commit into
Conversation
The serve command refuses to start without CYBERSTRIKE_SERVER_PASSWORD, but createCyberstrikeServer never supplied one, so SDK-managed startup (and script/duplicate-pr.ts, which relies on it) always failed with 'Error: CYBERSTRIKE_SERVER_PASSWORD is required'. Give the spawned server a password with precedence options.password > CYBERSTRIKE_SERVER_PASSWORD > randomUUID(), pass it via the child env (never argv), and send the matching Basic auth header from createCyberstrike so the client is authenticated for non-loopback use. Applied identically to v1 and v2; loopback trust and forwarded request detection are unchanged. Adds server.test.ts covering startup without the env var, 401 for forwarded requests without credentials, 200 with the generated password, explicit option and env password precedence, and v1/v2 client reachability.
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
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
Fixes
Error: CYBERSTRIKE_SERVER_PASSWORD is requiredwhen starting a server through the JS SDK (createCyberstrike/createCyberstrikeServer), which brokescript/duplicate-pr.ts— the script.github/workflows/pr-management.ymlinvokes with no password secret configured.Root cause
packages/cyberstrike/src/cli/cmd/serve.tsrefuses to start withoutCYBERSTRIKE_SERVER_PASSWORD(by design — the password protects non-loopback access, seeSECURITY.md). However,createCyberstrikeServerspawnedcyberstrike servewithout ever supplying one, so every SDK-managed startup failed immediately with:Fix
In
packages/sdk/js/src/{server,index}.tsand theirv2/twins:options.password→CYBERSTRIKE_SERVER_PASSWORD→randomUUID()(node:crypto, 122-bit CSPRNG), so explicit overrides and existing env-based setups keep working, while zero-configuration startup now just works.psoutput or logs.Authorization: Basicheader fromcreateCyberstrikeso the client is authenticated for non-loopback use.x-forwarded-for/cf-connecting-ip) detection, and Basic auth enforcement all behave exactly as before. No authentication is disabled or weakened; the only change is that the SDK now supplies the credential the server demands.Security considerations
node:crypto), and never written to disk, logs, or git.127.0.0.1by default; the password additionally protects proxied/tunneled access per existing middleware.401and only the matching credentials get200.Tests
packages/sdk/js:bun test src/server.test.ts→ 6 pass, 0 fail (13 expect calls) — startup without the env var, 401 on unauthorized forwarded requests, 200 with the generated password,options.passwordprecedence over env, env password compatibility, and v1/v2 client reachability.bun run typecheckclean; prettier clean;bun install --frozen-lockfile(CI mode) accepts the lockfile.Note:
script/duplicate-pr.ts's server now starts correctly, but the full duplicate-check workflow additionally requires the upstreamduplicate-pragent andCYBERSTRIKE_API_KEY, which are only available in CI — the model-response path could not be exercised locally and is not claimed to pass here.@types/bunwas added to the SDK's devDependencies (already in the workspace catalog) for thebun:testimport; the lockfile diff is that single line.Fixes #167