Files
seal-use/src/http/server.ts
T
yunyingk f8e083f3b2 Fix security scan findings: confirm gate, exit codes, redaction, CI tag env (#180)
- Gate rules push behind --yes at CLI and domain layers (fail-closed on
  dryRun=false without confirm)
- Raise webhook replay partial failure as CliError so exit 1 survives
  cli.ts exitCode overwrite; route webhook stdout through printJson for
  exit-12 protection and --output-file support
- Narrow MCP read-only allowlist: drop config mode/lint (write forms are
  indistinguishable under token-prefix matching; config get covers reads)
- Extract redactSensitiveText to core, extend credential patterns, apply
  to HTTP sendError/500 and domain error messages
- Pass release TAG_NAME via env instead of inline ${{ }} interpolation
  to close script injection through crafted tag names
- Track .zcodeignore so enterprise credential exclusions travel with the
  repo
- Add .agents/rules/security-posture.md documenting usability-first
  accepted risks (loopback adapter auth, update verification, mutation
  command gates, skill dump stdout); register skill dump as a documented
  stdout Markdown exception in AGENTS.md and cli-protocol.md
- Rebuild dist/mcp/server.js
2026-09-24 22:02:24 +08:00

48 lines
1.7 KiB
TypeScript

import { createServer, type Server } from "node:http";
import { handleHttpRequest } from "./routes.js";
import { redactSensitiveText } from "../core/redact.js";
import { VERSION } from "../version.js";
export type HttpServerOptions = {
port?: number;
host?: string;
silent?: boolean;
};
export const DEFAULT_HTTP_PORT = 8787;
export const DEFAULT_HTTP_HOST = "127.0.0.1";
export async function startHttpServer(options: HttpServerOptions = {}): Promise<Server> {
const port = options.port ?? (process.env.PORT ? Number.parseInt(process.env.PORT, 10) : DEFAULT_HTTP_PORT);
const host = options.host ?? (process.env.HOST ? process.env.HOST : DEFAULT_HTTP_HOST);
const server = createServer(async (req, res) => {
try {
await handleHttpRequest(req, res);
} catch (err) {
if (!res.headersSent) {
res.writeHead(500, { "Content-Type": "application/json" });
res.end(JSON.stringify({ error: true, message: redactSensitiveText(err instanceof Error ? err.message : String(err)) }));
}
}
});
return new Promise((resolve, reject) => {
server.on("error", (err) => {
reject(err);
});
server.listen(port, host, () => {
if (!options.silent) {
console.error(`\n🚀 seal-use HTTP Server (v${VERSION}) started`);
console.error(` URL: http://${host}:${port}`);
console.error(` Docs: http://${host}:${port}/docs`);
console.error(` OpenAPI: http://${host}:${port}/openapi.json`);
console.error(` CLI Exec: POST http://${host}:${port}/api/cli`);
console.error(` REST API: http://${host}:${port}/v1/...\n`);
}
resolve(server);
});
});
}