Documentation sections
Guard package · v2
Documentation
One package, two adapters, and an explicit application security boundary. Policy runs locally; synchronization and evidence reporting stay outside the request path.
Install
You need a site key and a secret. Both come from the setup screen when you register your domain. The secret is shown once and cannot be retrieved afterwards — if you lose it, rotate the key rather than trying to recover it.
npm install @pharoshub/guardPHAROS_SITE_KEY=st_your_key_here
PHAROS_SECRET=your_secret_here
PHAROS_COLLECTOR=https://www.pharoshub.cloud/api/ingestTreat PHAROS_SECRET like a database password. Anyone holding it can write into your evidence trail.
The package requires Node.js 18 or newer. Use the root export for Express and other Connect-compatible servers. Use @pharoshub/guard/nextfor Next.js Proxy or Middleware environments; that adapter uses Web Crypto and does not import Node’s crypto module.
Configuration reference
| Option | Default | Purpose |
|---|---|---|
| siteKey | required | Public site identifier used to select the signing key. |
| secret | required | Signs event batches and application honeytokens. Server-side only. |
| collector | PharosHub ingest URL | Override only for an approved private or test collector. |
| traps | 12 built-in paths | Replace the default application tripwire paths. |
| deception | false | Enable the adaptive decoy and automatic proof gate. |
| enforcement.enabled | false | Allow proven sources to be contained on protected routes. |
| enforcement.protectedRoutes | [] | Exact paths, wildcard children, and optional HTTP methods. |
| enforcement.ttlMs | 30 minutes | Local quarantine lifetime, clamped between 1 minute and 24 hours. |
| trustProxy | false | Trust the leftmost forwarded address only behind a proxy that overwrites it. |
| captureBodies | false | Capture a bounded body on trap routes only; never on real routes. |
| onEvent | — | Optional local callback for each evidence or prevention event. |
Do not enable trustProxy merely because a forwarded header exists. Your load balancer or CDN must remove the visitor-supplied value and write its own. Otherwise an attacker can choose the identity used by any IP-based security control.
Runtime API
guard.middleware()
Express or Connect middleware. Mount before application routes.
guard.honeytoken(label)
Mint a signed canary that remains verifiable across restarts for 90 days.
guard.reportHoneytokenUse({ token, req })
Verify a presented canary and contain its source when valid.
guard.reportAuth({ accountHash, success, req })
Report a privacy-preserving authentication outcome.
guard.contain(sourceIp, reason)
Open the configured quarantine from application-owned proof.
guard.release(sourceIp)
Remove the current process decision immediately.
guard.decision({ sourceIp, path, method })
Inspect the local policy result without writing a response.
guard.flush()
Send the final queued batch during a graceful shutdown.
guard.beaconTag(nonce?)
Return the clone-detection script tag, with an optional CSP nonce.
The Next.js adapter returns one guard function rather than the Express object API. It answers with a Response only for a trap or a contained protected action; otherwise it returns null so your application continues normally.
Active containment
Containment is opt-in and route-scoped. List the application paths where a request from a proven attacker becomes costly. A bad reputation score can never open this gate: it requires repeated distinct tripwires, corroborated exploit behavior, or use of a honeytoken nobody legitimate holds.
const guard = createGuard({
siteKey: process.env.PHAROS_SITE_KEY,
secret: process.env.PHAROS_SECRET,
deception: true,
enforcement: {
enabled: true,
protectedRoutes: [
"/admin/*",
"/account/security/*",
{ path: "/api/payments", methods: ["POST", "DELETE"] },
],
ttlMs: 30 * 60 * 1000,
},
});String routes match exactly. A route ending in /* covers the path and its children. Add methods when reads should remain available but mutations must stop.
What happens after proof
- ✓The current process quarantines the source immediately.
- ✓Requests to configured routes receive a 403 with x-pharos-action: contained.
- ✓Public and unlisted routes remain available to the same source.
- ✓The decision synchronizes to other instances with the next signed event batch.
- ✓Every prevented action is recorded; the quarantine expires automatically.
No PharosHub API call occurs while deciding a request. If our service is unavailable, the locally cached decision continues until its TTL and ordinary application traffic does not wait.
Application-owned proof
If your own code has definitive evidence—a business-specific canary, for example—you can open and release the same bounded quarantine directly.
guard.contain(sourceIp, "checkout_canary_used");
// Release immediately after operator review
guard.release(sourceIp);Hallmark — sealing your pages
Hallmark signs your site when you build it, and every visitor’s browser checks that signature against what was actually delivered. It answers the one question no firewall can: has anything on my site been changed since I published it?
The realistic attack is not defacement. It is one line — a reservations number swapped for someone else’s, a payment block added to a page, two digits changed in an account number. The page loads perfectly and every request is legitimate, so nothing else in a normal security stack is looking.
Add it to your build, after your site is generated:
import { hallmark } from "@pharoshub/guard/hallmark";
await hallmark({ dir: "dist" }); // or "out", "build", ".output/public"It fingerprints every published file, asks us to sign the list, and writes two files into your output: _integrity.json (the signed list) and integrity.js (the verifier). Your CDN serves both like any other file. The verifier is written before fingerprinting, so it is sealed too — a verifier outside the seal is one an attacker could quietly replace with a no-op.
Then load the verifier on your pages:
<script src="/integrity.js" defer></script>What leaves your infrastructure
A list of paths and SHA-256 fingerprints. Never the files themselves. Your build hashes its own output, so your site never reaches us, cannot be exfiltrated here, and a large site costs no more to seal than a small one.
Why we can make this promise
The signing key is not on your servers, not in your build, not at your CDN, and not in our database. Someone who takes over all of it can change whatever they like — they cannot produce a signature that verifies. Verification uses a public key that can only check, never sign, so anyone can audit a page independently without an account.
What gets checked
The HTML document, plus the same-origin scripts and stylesheets that page actually loaded. Scripts matter as much as markup: a swapped JavaScript bundle is how card skimming is done, and checking only the document would miss it entirely.
Third-party scripts are deliberately not checked. They are not yours to seal, they change without warning, and flagging them would produce findings you can neither explain nor fix.
It reports; it does not block
A mismatch is usually innocent — a corporate proxy that rewrites HTML, an antivirus, an ISP banner, or a deploy landing while somebody had the old page open. So Hallmark reports and never stops a page loading for your visitors. What distinguishes an attack is scale: one visitor is their network, thousands of visitors across unrelated networks is the file. You are emailed once a finding passes that threshold, not on the first report.
When it stops
The seal carries an expiry inside the signature, set from your subscription plus a fortnight’s grace. It cannot be extended by editing the file — that breaks the signature. Renewing and redeploying reseals; renewing without deploying reseals too.
If it cannot seal
Every failure is open. No keys, no network, our service down, subscription lapsed — the build prints a warning and finishes. A security feature that can stop you deploying is a worse problem than the one it solves. Check your build log for sealed N files; anything else prints the reason.
Express
Mount it before your own routes. Anything mounted earlier answers first, and a trap path that your router handles is a trap that never fires.
import express from "express";
import { createGuard } from "@pharoshub/guard";
const app = express();
const guard = createGuard({
siteKey: process.env.PHAROS_SITE_KEY,
secret: process.env.PHAROS_SECRET,
deception: true,
// Enable only when your proxy overwrites X-Forwarded-For.
trustProxy: true,
enforcement: {
enabled: true,
protectedRoutes: ["/admin/*", "/api/internal/*"],
},
});
app.use(guard.middleware());
// ... your own routes below
process.on("SIGTERM", async () => {
// Flush the last batch instead of losing it on shutdown.
await guard.flush();
process.exit(0);
});Next.js
Next middleware runs on the Edge runtime, where Node’s crypto module does not exist — so the adapter is a separate implementation built on Web Crypto. Import it from @pharoshub/guard/next, not the root.
import { NextResponse, type NextFetchEvent } from "next/server";
import { createNextGuard } from "@pharoshub/guard/next";
const guard = createNextGuard({
enforcement: {
enabled: true,
protectedRoutes: ["/admin/*", "/api/internal/*"],
},
});
export async function proxy(request: Request, event: NextFetchEvent) {
// Returns a Response for a trap or contained protected action; otherwise
// null, so your own routing stays in control.
return (await guard(request, event)) ?? NextResponse.next();
}
export const config = { matcher: "/:path*" };Deployment model matters. A long-lived Next.js Node process can retain local policy state like Express. An edge or serverless isolate may be recycled at any time, so a cold isolate starts without prior in-memory decisions and learns shared state only after a signed report. Keep your edge controls in place when you require globally consistent denial from the first request.
The clone beacon
A copied page copies this tag with it, so the copy asks us for the script and tells us which host it is serving. Put it in your document head on every public page.
<script
src={`https://www.pharoshub.cloud/b/${process.env.PHAROS_SITE_KEY}.js`}
async
defer
/>Running a Content-Security-Policy with a nonce? Pass it through: guard.beaconTag(nonce) returns the whole tag with the nonce applied.
The beacon reads three values that are already public — the hostname, the path, and the referrer — and sends them once. It sets no cookies, reads no storage, and does not fingerprint anyone.
Honeytokens
A credential that looks real and is never valid. Put it where an intruder will only find it by looking somewhere they should not — a stale config file, an HTML comment, a decoy admin page.
const token = guard.honeytoken("stripe");
// -> a signed pk_live_... canary, valid across process restarts
// In the endpoint where a submitted canary key would appear:
const proven = guard.reportHoneytokenUse({ token: req.body.apiKey, req });
// A valid token opens the configured quarantine for the request source.Nobody legitimate holds one, so its use is not a signal to weigh. It is proof. Tokens are signed with your site secret, expire after 90 days, and a modified or unknown value cannot create a decision. A token is accepted once per running instance.
Tuning trap paths
Twelve sensible defaults ship with the package — /.env, /wp-admin, /backup.zip and similar. The best traps, though, are the ones specific to you: a path that looks like it belongs to your stack and that no link points at.
import { createGuard, DEFAULT_TRAPS } from "@pharoshub/guard";
const guard = createGuard({
siteKey: process.env.PHAROS_SITE_KEY,
secret: process.env.PHAROS_SECRET,
traps: [...DEFAULT_TRAPS, "/staff-portal", "/customer-export.csv"],
});Your plan sets how many you may run — 12 on Defend, 40 on Control. Make sure a real visitor can never reach one by following a link, or you will be investigating your own marketing team.
The same honesty about your own tooling: an uptime monitor that crawls every path, a vulnerability scanner you run, or a penetration test you commission will spring traps exactly as an intruder would — that is the traps working, not failing. Point your own tools away from trap paths where you can, and when you cannot, close those incidents as your own from the console; the distinction is recorded, which matters if a real alert is ever questioned later.
Sign-in reporting
Credential stuffing is invisible in any single request — it is a shape across many, and that shape only becomes readable if outcomes are reported. Call this from your own sign-in handler on Control and above.
import { createHash } from "node:crypto";
// YOU hash the identifier. We never receive an email address, and there is
// no parameter for anything password-derived.
const accountHash = createHash("sha256")
.update(email.toLowerCase() + process.env.MY_SALT)
.digest("hex");
guard.reportAuth({ accountHash, success: false, req });Because the hash is yours and salted with your own secret, we can tell you that one address failed against forty accounts without ever being able to work out whose. That is what makes it safe for us to hold at all.
Three shapes become detectable once this is wired: spraying (one source, many accounts), stuffing (many sources, one credential list), and takeover — failures against an account followed by a success from an address that has never signed into it before, which is the one that has already happened.
What it sends
Only requests that were already suspicious. A normal request never reaches the reporting path at all.
| Field | Example |
|---|---|
| path | /.env |
| method | GET |
| source_ip | 203.0.113.9 |
| user_agent | python-requests/2.31 |
| referer | — |
| observed_at | 2026-08-16T03:14:02Z |
Request bodies are not captured unless you pass captureBodies: true, and even then only for trap routes. A body on your real routes can contain your users’ private data, and those are yours.
How it fails
This runs in front of production application traffic. If it throws, hangs, or slows a request, it has done more damage than the attacks it detects — so every failure mode below is a structural property of the package rather than a policy.
- Missing key or secretThe guard becomes a no-op and says so once at startup.
- Collector unreachableLocal containment continues from cached state; events queue in bounded memory and retry.
- Subscription lapsedThe collector answers 402. The package stops retrying rather than hammering us for a month.
- Anything throwsThe request continues exactly as if the guard were not installed.
An internal error fails open rather than taking down the application. A collector outage does not disable a local quarantine already in force.
Troubleshooting
+ − The setup screen never turns green
The guard only reports when something suspicious happens, plus a heartbeat. Request one of your own trap paths — curl https://yoursite.com/.env — and it should flip within a minute. If it does not, check that the middleware is mounted before your routes.
+ − I get 401 unauthorised in my logs
The signature covers the exact request body, so a proxy that rewrites bodies will break it. Also check your server clock: reports more than five minutes out of step are refused, and that shows up as 408 rather than 401.
+ − A trap path is firing on real visitors
Something links to it. Search your own markup and your sitemap. A trap a visitor can reach by clicking is not a trap.
+ − I lost the secret
Rotate the site key from the Protection screen and update your environment. There is no recovery path, by design — a credential that can write into an evidence trail should not be recoverable by anyone who can read a support ticket.
Stuck on something not covered here? Email support@pharoshub.cloud — a person who has read the code will answer.