/**
 * The `codegraph ui` server's security boundary.
 *
 * Threat model, stated plainly: this process serves a browser-readable view of
 * the user's SOURCE CODE from a port on their machine. It binds loopback, so
 * nothing on the network can reach it. That leaves one realistic attack —
 * **DNS rebinding**: any page the user visits can point `evil.example` at
 * `127.0.0.1` and then have the browser issue same-origin requests to us. The
 * browser will happily connect; the only thing that distinguishes the attacker's
 * request from the viewer's own is the `Host` header, which the browser fills in
 * from the URL and script cannot forge.
 *
 * So the rules are:
 *
 * - **`Host` must be a loopback name** (`localhost`, `127.0.0.1`, `[::1]`) and,
 *   if it carries a port, that port must be ours. Anything else is 403.
 * - **`Origin`, when present, must be loopback too.** Belt and braces: absent on
 *   the viewer's own same-origin GETs, and present-and-foreign only on a
 *   cross-site request we want nothing to do with.
 * - **No CORS headers, ever.** Not adding `Access-Control-Allow-Origin` is what
 *   keeps a cross-origin reader from seeing a response body even if it does
 *   reach us. There is deliberately no way to turn this on.
 * - **GET/HEAD everywhere; POST/DELETE only under `/api/`, and only for a
 *   request that could not have been forged by a form.** See
 *   {@link isWriteRequest} below — the viewer went from a pure reader to one
 *   that saves trails into `.codegraph/ui/`, and that is the entire change to
 *   this boundary.
 * - **Every path resolves through {@link validatePathWithinRoot}** — the same
 *   chokepoint the MCP read sinks use, which catches `../` traversal AND
 *   in-tree symlinks pointing out of the root (#527).
 */
import { PathRefusalError } from '../errors';
export { PathRefusalError };
/** Methods that answer anywhere: the viewer's assets and every read endpoint. */
export declare const READ_METHODS: readonly string[];
/**
 * Methods that answer under `/api/` only, and only for a request carrying
 * {@link WRITE_HEADER}. The viewer's one write is a saved trail.
 */
export declare const WRITE_METHODS: readonly string[];
/** HTTP methods the viewer server answers at all. Everything else is 405. */
export declare const ALLOWED_METHODS: readonly string[];
/**
 * The header a write has to carry.
 *
 * Belt and braces behind the `Host` and `Origin` checks, and worth the two
 * lines because it fails *differently*: a custom request header cannot be sent
 * cross-origin without a CORS preflight, and this server answers no preflight
 * and sends no `Access-Control-*` header, so the browser never issues the real
 * request. That closes the one shape those checks lean on a header for — a
 * `<form method="post">` submitted from another page, which sends no `Origin`
 * in some older browsers and cannot set a custom header in any of them.
 */
export declare const WRITE_HEADER = "x-codegraph-ui";
export declare function isWriteMethod(method: string): boolean;
/**
 * Whether a mutating request is one the viewer could have made.
 *
 * @param method     the request method, already known to be a write method
 * @param pathname   the raw request path
 * @param headers    `x-codegraph-ui` and, for a body-carrying method, `content-type`
 */
export declare function isWriteRequest(pathname: string, headers: {
    marker: string | undefined;
    contentType: string | undefined;
}): {
    ok: true;
} | {
    ok: false;
    reason: string;
};
/**
 * Whether a request's `Host` header names this loopback server.
 *
 * A missing `Host` is rejected: HTTP/1.1 requires it, and the one client that
 * may legally omit it (HTTP/1.0) is not a browser we need to serve.
 */
export declare function isAllowedHost(host: string | undefined, port: number): boolean;
/**
 * Whether a request's `Origin` header is acceptable.
 *
 * An ABSENT `Origin` is allowed — browsers omit it on same-origin GETs, which
 * is every request the viewer makes. A present one must be loopback-on-our-port;
 * the literal `null` origin (sandboxed iframe, `file://` page) is refused.
 */
export declare function isAllowedOrigin(origin: string | undefined, port: number): boolean;
/**
 * Whether a raw request path is worth resolving at all.
 *
 * Rejects any `..` segment outright rather than letting containment sort it
 * out later. Containment WOULD catch it — but the SPA fallback sits behind
 * containment, so `GET /../../etc/passwd` would otherwise be answered with the
 * app shell (a 200) instead of the 404 a traversal attempt deserves. Nothing
 * outside the root leaks either way; this just stops the server from
 * pretending a hostile path was an ordinary route.
 *
 * Takes the RAW path from `req.url`, before WHATWG URL parsing folds `..`
 * segments away — that folding is what would hide the attempt.
 */
export declare function isSafeRequestPath(rawPath: string): boolean;
/**
 * Resolve a request path to a file inside the static asset root.
 *
 * Returns the absolute path, or `null` for anything that is not a readable file
 * inside `rootDir` — a traversal attempt, a symlink escape, a directory, a
 * missing file. Callers turn `null` into a 404 (never a 403): telling a prober
 * which of those it hit is free information.
 *
 * Percent-decoding happens HERE, before containment is checked, so an encoded
 * `..%2f` is caught by the same guard as a literal `../`.
 */
export declare function resolveStaticAsset(rootDir: string, urlPath: string): string | null;
/**
 * Resolve a project-relative source path to an absolute path that is safe to
 * read and hand to the browser.
 *
 * This is the single read chokepoint for anything served OUT OF THE USER'S
 * REPOSITORY (as opposed to the viewer's own bundled assets). The JSON API
 * built on top of this server must route every file read through it — that is
 * what keeps `/api/source?path=../../.ssh/id_rsa` from being a credential leak
 * over a port the user opened to read their own code.
 *
 * @throws {PathRefusalError} when the root is a sensitive system directory, or
 *   the path escapes the root by traversal or symlink.
 */
export declare function resolveProjectFile(projectRoot: string, relativePath: string): string;
//# sourceMappingURL=security.d.ts.map