Skip to content

An open-source, faster Devin alternative

TypeScript

feat(cve-swarm): authenticated scans with a throwaway test account

Mohamed Habib via Computere5e55dfbe483
diff --git a/web/src/managed-agents/security/SecurityOnboarding.tsx b/web/src/managed-agents/security/SecurityOnboarding.tsx
index 590985d8..6f15ca9a 100644
--- a/web/src/managed-agents/security/SecurityOnboarding.tsx
+++ b/web/src/managed-agents/security/SecurityOnboarding.tsx
@@ -49,11 +49,18 @@ import {
SEED_CVES,
serializeRunManifest,
swarmCells,
+ SWARM_LOGIN_PASSWORD_VAR,
+ SWARM_LOGIN_USERNAME_VAR,
type LaunchedCell,
type SwarmCell,
type SwarmPayload,
} from './catalog'
+// The throwaway test-account credentials, carried from the form to the launch
+// handler out-of-band from SwarmPayload so they never reach the cell prompt or
+// the run manifest. They go only to the project's encrypted runtime variables.
+type SwarmCredentials = { username: string; password: string }
+
// Each cell is one microVM session, so cap the matrix to keep an accidental
// 20×20 launch from spinning up hundreds of sandboxes at once.
const MAX_SWARM_CELLS = 24
@@ -357,9 +364,13 @@ export default function SecurityOnboarding() {
// as it comes up. The manifest is the source of truth across the route change —
// the ids don't survive in React state.
const launch = useMutation({
- mutationFn: async (
- payload: SwarmPayload,
- ): Promise<{
+ mutationFn: async ({
+ payload,
+ credentials,
+ }: {
+ payload: SwarmPayload
+ credentials: SwarmCredentials | null
+ }): Promise<{
projectId: string
runId: string
agentId: string
@@ -380,6 +391,28 @@ export default function SecurityOnboarding() {
// operator reaches launch before it settles, await that same deploy rather
// than blocking the whole flow on it earlier.
const project = deployed ?? (await startDeploy())
+ // Authenticated scan: stash the throwaway account in the project's
+ // encrypted runtime variables so every cell's sandbox gets them in its
+ // environment. Project-scoped (no agentId) so all cells inherit one login;
+ // `default` is the environment managed-template projects run in (the same
+ // one the GitHub install is attached to above). Never written to the
+ // manifest or the prompt.
+ if (credentials) {
+ await Promise.all([
+ putAgentRuntimeVariable({
+ projectId: project.projectId,
+ environment: 'default',
+ name: SWARM_LOGIN_USERNAME_VAR,
+ value: credentials.username,
+ }),
+ putAgentRuntimeVariable({
+ projectId: project.projectId,
+ environment: 'default',
+ name: SWARM_LOGIN_PASSWORD_VAR,
+ value: credentials.password,
+ }),
+ ])
+ }
const runId = `run-${crypto.randomUUID()}`
const agentId = `${project.projectAgentId}@default`
const starting: LaunchedCell[] = cells.map((cell) => ({
@@ -492,7 +525,9 @@ export default function SecurityOnboarding() {
availableRepos={connectedRepos.data ?? []}
reposLoading={connectedRepos.isLoading}
launching={launch.isPending}
- onLaunch={(payload) => launch.mutate(payload)}
+ onLaunch={(payload, credentials) =>
+ launch.mutate({ payload, credentials })
+ }
/>
</StepCard>
</div>
@@ -644,10 +679,15 @@ function PayloadBuilder({
availableRepos: string[]
reposLoading: boolean
launching: boolean
- onLaunch: (payload: SwarmPayload) => void
+ onLaunch: (payload: SwarmPayload, credentials: SwarmCredentials | null) => void
}) {
const [target, setTarget] = useState('')
const [declaration, setDeclaration] = useState(false)
+ // Optional throwaway test account, so a cell can log in and scan behind the
+ // auth wall. Empty = unauthenticated scan, exactly as before.
+ const [loginUrl, setLoginUrl] = useState('')
+ const [loginUsername, setLoginUsername] = useState('')
+ const [loginPassword, setLoginPassword] = useState('')
const [repositories, setRepositories] = useState<string[]>([])
// Prefill every CVE in this week's feed so a first swarm runs with no typing.
const [cveIds, setCveIds] = useState<string[]>(() =>
@@ -655,6 +695,13 @@ function PayloadBuilder({
)
const [preview, setPreview] = useState<string | null>(null)
+ // A login needs both a username and a password; the URL is optional (the cell
+ // can find the login page itself). Only then is the scan authenticated.
+ const authenticated = loginUsername.trim() !== '' && loginPassword !== ''
+ const credentials: SwarmCredentials | null = authenticated
+ ? { username: loginUsername.trim(), password: loginPassword }
+ : null
+
const payload: SwarmPayload = useMemo(
() => ({
target: target.trim(),
@@ -662,8 +709,11 @@ function PayloadBuilder({
repositories,
cveIds,
model: DEFAULT_SWARM_MODEL,
+ authenticated,
+ // Non-secret, so it may ride in the payload; the username/password do not.
+ ...(loginUrl.trim() ? { loginUrl: loginUrl.trim() } : {}),
}),
- [target, declaration, repositories, cveIds],
+ [target, declaration, repositories, cveIds, authenticated, loginUrl],
)
// Default to every connected repo the moment the list lands — the operator
@@ -681,6 +731,12 @@ function PayloadBuilder({
// of "this web application" — so a launch needs a real https(s) URL. An empty
// or malformed target blocks the button.
const targetValid = /^https?:\/\/.+/i.test(payload.target)
+ // A login URL is optional, but if given it must be a real http(s) URL.
+ const loginUrlValid = loginUrl.trim() === '' || /^https?:\/\/.+/i.test(loginUrl.trim())
+ // Credentials are all-or-nothing: a half-filled login would silently scan
+ // unauthenticated, so block the launch until both fields are set or both empty.
+ const loginComplete =
+ (loginUsername.trim() === '') === (loginPassword === '')
// Each cell is one sandbox, so a repository × CVE matrix past the cap is a
// launch we won't start — surface it before the click, not on it.
const cellCount = repositories.length * cveIds.length
@@ -691,13 +747,15 @@ function PayloadBuilder({
cveIds.length > 0 &&
repositories.length > 0 &&
!overCap &&
- targetValid
+ targetValid &&
+ loginUrlValid &&
+ loginComplete
return (
<div className="space-y-5">
<Field
label="Endpoint to scan"
- hint="A public URL you operate — required. Passive only: plain GETs on public paths and banner headers. No payloads, no auth probing."
+ hint="A URL you operate — required. The swarm discovers routes from your repos and probes this host only. Add a test login below to scan behind the auth wall."
>
<Input
type="url"
@@ -713,6 +771,46 @@ function PayloadBuilder({
) : null}
</Field>
+ <Field
+ label="Test login (optional)"
+ hint="Use a throwaway account you create just for this — the swarm signs in with it and scans behind the login, exercising the app and its API to find vulnerabilities. Credentials are stored as encrypted runtime variables, never shown again or written to findings. Leave blank to scan only what's reachable without signing in."
+ >
+ <div className="grid gap-2 sm:grid-cols-2">
+ <Input
+ type="text"
+ autoComplete="off"
+ placeholder="Username or email"
+ value={loginUsername}
+ onChange={(e) => setLoginUsername(e.target.value)}
+ />
+ <Input
+ type="password"
+ autoComplete="new-password"
+ placeholder="Password"
+ value={loginPassword}
+ onChange={(e) => setLoginPassword(e.target.value)}
+ />
+ </div>
+ <Input
+ type="url"
+ className="mt-2"
+ placeholder="Login page URL (optional)"
+ value={loginUrl}
+ onChange={(e) => setLoginUrl(e.target.value)}
+ aria-invalid={!loginUrlValid}
+ />
+ {!loginComplete ? (
+ <span className="text-destructive text-xs">
+ Enter both a username and a password, or leave both blank.
+ </span>
+ ) : null}
+ {!loginUrlValid ? (
+ <span className="text-destructive text-xs">
+ Enter a full http(s) URL, or leave the login page blank.
+ </span>
+ ) : null}
+ </Field>
+
<Field
label="Repositories"
hint="Every repo from your GitHub install, selected by default. Each repository is checked against each CVE as its own parallel cell."
@@ -786,7 +884,7 @@ function PayloadBuilder({
<div className="flex items-center gap-3">
<Button
disabled={!ready || launching || deployState === 'failed'}
- onClick={() => onLaunch(payload)}
+ onClick={() => onLaunch(payload, credentials)}
>
{launching ? <Loader2 className="animate-spin" /> : <Radar />}
Launch swarm
diff --git a/web/src/managed-agents/security/catalog.test.ts b/web/src/managed-agents/security/catalog.test.ts
index 671c1b0a..ec1ecb1b 100644
--- a/web/src/managed-agents/security/catalog.test.ts
+++ b/web/src/managed-agents/security/catalog.test.ts
@@ -83,6 +83,27 @@ describe('swarm fan-out', () => {
expect(prompt).not.toContain('scan_surface')
expect(prompt).toContain('reachable in this code')
})
+
+ it('tells the cell to log in when the scan is authenticated', () => {
+ const prompt = composeCellPrompt(
+ { ...payload, authenticated: true, loginUrl: 'https://app.example.com/login' },
+ { repository: 'acme/web', cveId: 'CVE-2026-1' },
+ )
+ // Reads the creds from the environment, never carries them.
+ expect(prompt).toContain('SWARM_LOGIN_USERNAME')
+ expect(prompt).toContain('SWARM_LOGIN_PASSWORD')
+ expect(prompt).toContain('https://app.example.com/login')
+ expect(prompt).toContain('--no-sandbox')
+ })
+
+ it('says nothing about logging in for an unauthenticated scan', () => {
+ const prompt = composeCellPrompt(payload, {
+ repository: 'acme/web',
+ cveId: 'CVE-2026-1',
+ })
+ expect(prompt).not.toContain('SWARM_LOGIN_USERNAME')
+ expect(prompt).not.toContain('log in')
+ })
})
describe('parseCellFinding', () => {
diff --git a/web/src/managed-agents/security/catalog.ts b/web/src/managed-agents/security/catalog.ts
index a0d6b23e..921708ec 100644
--- a/web/src/managed-agents/security/catalog.ts
+++ b/web/src/managed-agents/security/catalog.ts
@@ -78,8 +78,22 @@ export type SwarmPayload = {
readonly repositories: readonly string[]
readonly cveIds: readonly string[]
readonly model: string
+ // Authenticated discovery. These two are non-secret: a flag that a login is
+ // required, and the page to log in on. The throwaway account's actual username
+ // and password NEVER travel in the payload — they would land in the cell
+ // prompt and the run manifest, both of which are stored. They go to the
+ // project's encrypted runtime variables instead (SWARM_LOGIN_*), and the cell
+ // reads them from its environment at run time.
+ readonly authenticated?: boolean
+ readonly loginUrl?: string
}
+// Encrypted runtime-variable names the onboarding writes and every cell reads
+// from its environment to log in. Shared here so the writer and the prompt that
+// tells the agent to read them can never drift apart.
+export const SWARM_LOGIN_USERNAME_VAR = 'SWARM_LOGIN_USERNAME'
+export const SWARM_LOGIN_PASSWORD_VAR = 'SWARM_LOGIN_PASSWORD'
+
// A single unit of swarm work: one repository checked against one CVE. The
// launch fans the payload's repository × CVE matrix into one cell per pair, and
// starts one bound session for each so they run in parallel and each writes its
@@ -261,6 +275,21 @@ export function discoveryLines(target: string): string[] {
// intelligence, derive the repo's routes, probe the attested target, and keep
// evidence. The worker collapses to a single hunt when the payload names one
// repository and one CVE.
+// When the operator supplied a throwaway test account, tell the cell to log in
+// first and scan behind the auth wall. The credentials themselves are NOT here —
+// they are in the environment as encrypted runtime variables; the prompt only
+// names them so the agent reads them itself. Empty when the scan is unauthenticated.
+function authenticatedLoginLines(payload: SwarmPayload): string[] {
+ if (!payload.authenticated) return []
+ const where = payload.loginUrl
+ ? `the login page ${payload.loginUrl}`
+ : "the target's login page"
+ return [
+ `This target requires a login, and a throwaway test account has been provisioned for you. Its credentials are in the environment variables ${SWARM_LOGIN_USERNAME_VAR} and ${SWARM_LOGIN_PASSWORD_VAR}. Before anything else, drive the preinstalled headless browser (Playwright, launched with --no-sandbox) to ${where}, sign in with those credentials, and save the authenticated session (storageState / cookies). Reuse that session for every page load, API call and scanner request so all discovery runs as the logged-in account. Treat the account as disposable and in-scope: exercise the app and its API to find vulnerabilities, but stay within this host. Never print the credentials or copy them into findings, logs or a pull request.`,
+ '',
+ ]
+}
+
export function composeCellPrompt(payload: SwarmPayload, cell: SwarmCell): string {
const lines = [
'Launch a CVE swarm cell against my own assets.',
@@ -275,6 +304,7 @@ export function composeCellPrompt(payload: SwarmPayload, cell: SwarmCell): strin
'',
...feedSeedingLines(),
'',
+ ...authenticatedLoginLines(payload),
...discoveryLines(payload.target),
'If the verdict is EXPOSED, open_fix_pull_request (dependency-only, single pin). Honor PUBLISH_ENABLED — dry run unless it is enabled.',
].filter((line): line is string => line !== null)