saferprompt 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/DOCKER.md CHANGED
@@ -52,6 +52,7 @@ The container has two environment variables baked in via the Dockerfile:
52
52
  |---|---|---|
53
53
  | `LOCAL_MODELS_ONLY` | `true` | When `true`, the app uses only the model baked into the image and makes no network requests to HuggingFace. Set to `false` if you want the app to fetch model updates at startup. |
54
54
  | `PORT` | `3000` | The port the Fastify server listens on inside the container. |
55
+ | `HOST` | `0.0.0.0` | The network interface to bind to. Use `127.0.0.1` for localhost only, or a specific IP. |
55
56
 
56
57
  There is also an optional variable not set by default:
57
58
 
@@ -63,6 +64,7 @@ There is also an optional variable not set by default:
63
64
  | `TLS_KEY_FILE` | *(unset)* | Path to PEM-encoded private key file inside the container. |
64
65
  | `TLS_CERT` | *(unset)* | Inline PEM certificate content (fallback if `TLS_CERT_FILE` not set). |
65
66
  | `TLS_KEY` | *(unset)* | Inline PEM private key content (fallback if `TLS_KEY_FILE` not set). |
67
+ | `DISABLE_UI` | *(unset)* | Set to `true` or `1` to disable the HTML test UI on `GET /`. |
66
68
 
67
69
  ### Overriding environment variables at runtime
68
70
 
package/PROTOCOLCONFIG.md CHANGED
@@ -6,6 +6,8 @@ SaferPrompt supports HTTP/1.1, HTTPS, and HTTP/2 via environment variables. No c
6
6
 
7
7
  | Variable | Default | Description |
8
8
  |---|---|---|
9
+ | `DISABLE_UI` | *(unset)* | Set to `true` or `1` to disable the HTML test UI on `GET /` |
10
+ | `HOST` | `0.0.0.0` | Network interface to bind to (`0.0.0.0` for all, `127.0.0.1` for localhost only, or a specific IP) |
9
11
  | `HTTP2` | *(unset)* | Set to `true` or `1` to enable HTTP/2 |
10
12
  | `TLS_CERT_FILE` | *(unset)* | Path to a PEM-encoded certificate file |
11
13
  | `TLS_KEY_FILE` | *(unset)* | Path to a PEM-encoded private key file |
package/README.md CHANGED
@@ -56,9 +56,9 @@ const result = await detect("What is the capital of France?");
56
56
  npm start
57
57
  ```
58
58
 
59
- This starts a Fastify server on port 3000 (override with `PORT` env var). It provides:
59
+ This starts a Fastify server on port 3000 (override with `PORT` env var), listening on all interfaces by default (override with `HOST` env var). It provides:
60
60
 
61
- - **`GET /`** — A web UI for testing prompts interactively
61
+ - **`GET /`** — A web UI for testing prompts interactively (disable with `DISABLE_UI=true`)
62
62
  - **`POST /api/detect`** — JSON API
63
63
 
64
64
  ```bash
@@ -238,6 +238,28 @@ Requests without the header (or with an incorrect value) return:
238
238
  { "error": "Invalid or missing x-api-key header" }
239
239
  ```
240
240
 
241
+ ### `DISABLE_UI`
242
+
243
+ Set to `true` or `1` to disable the HTML test UI served on `GET /`. When disabled, the route returns a `404` JSON response. The `/api/detect` endpoint is unaffected.
244
+
245
+ ```bash
246
+ DISABLE_UI=true npm start
247
+ ```
248
+
249
+ ### `HOST`
250
+
251
+ Controls which network interface the server binds to. Defaults to `0.0.0.0` (all interfaces).
252
+
253
+ | Value | Behavior |
254
+ |---|---|
255
+ | `0.0.0.0` | Listen on all interfaces (default) |
256
+ | `127.0.0.1` or `localhost` | Localhost only — not reachable from other machines |
257
+ | A specific IP (e.g., `192.168.1.50`) | Listen only on that interface |
258
+
259
+ ```bash
260
+ HOST=127.0.0.1 npm start
261
+ ```
262
+
241
263
  ## Additional Documentation
242
264
 
243
265
  - [Protocol Configuration](https://github.com/mikemainguy/saferprompt/blob/main/PROTOCOLCONFIG.md) — HTTP/2 and TLS setup guide
package/createApp.js CHANGED
@@ -9,12 +9,14 @@ import { logResult } from "./logger.js";
9
9
  * @param {string} [config.apiKey] — require this key in x-api-key header
10
10
  * @param {string} [config.responseMode] — "body" | "headers" | "both"
11
11
  * @param {number} [config.headersSuccessCode] — 200 or 204 (only relevant for "headers" mode)
12
+ * @param {boolean} [config.disableUi] — disable the HTML test UI on GET /
12
13
  * @param {object} [config.fastifyOpts] — extra Fastify constructor options (http2, https, etc.)
13
14
  */
14
15
  export function createApp({
15
16
  apiKey = "",
16
17
  responseMode = "body",
17
18
  headersSuccessCode = 200,
19
+ disableUi = false,
18
20
  fastifyOpts = {},
19
21
  } = {}) {
20
22
  const fastify = Fastify(fastifyOpts);
@@ -32,7 +34,12 @@ export function createApp({
32
34
  }
33
35
  });
34
36
 
35
- // Serve the test UI
37
+ // Serve the test UI (unless disabled)
38
+ if (disableUi) {
39
+ fastify.get("/", async (_request, reply) => {
40
+ reply.code(404).send({ error: "UI is disabled" });
41
+ });
42
+ } else {
36
43
  fastify.get("/", async (_request, reply) => {
37
44
  reply.type("text/html").send(`<!DOCTYPE html>
38
45
  <html lang="en">
@@ -96,6 +103,7 @@ export function createApp({
96
103
  </body>
97
104
  </html>`);
98
105
  });
106
+ }
99
107
 
100
108
  // API endpoint
101
109
  fastify.post("/api/detect", async (request, reply) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saferprompt",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Detect prompt injection attacks using the qualifire/prompt-injection-sentinel model",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -16,7 +16,7 @@
16
16
  "test": "node --test",
17
17
  "test:coverage": "node --test --experimental-test-coverage",
18
18
  "docker:build": "docker build --no-cache -t michaelmainguy/saferprompt:latest -t michaelmainguy/saferprompt:$(node -p \"require('./package.json').version\") .",
19
- "docker:publish": "npm run docker:build && docker push michaelmainguy/saferprompt",
19
+ "docker:publish": "docker buildx build --platform linux/amd64,linux/arm64 --no-cache -t michaelmainguy/saferprompt:latest -t michaelmainguy/saferprompt:$(node -p \"require('./package.json').version\") --push .",
20
20
  "npm:publish": "npm publish"
21
21
  },
22
22
  "keywords": [
package/server.js CHANGED
@@ -5,10 +5,12 @@ import { createApp } from "./createApp.js";
5
5
  import { getActiveDestinations } from "./logger.js";
6
6
 
7
7
  const PORT = process.env.PORT || 3000;
8
+ const HOST = process.env.HOST || "0.0.0.0";
8
9
  const API_KEY = process.env.API_KEY || "";
9
10
  const HTTP2 = process.env.HTTP2 === "true" || process.env.HTTP2 === "1";
10
11
  const RESPONSE_MODE = (process.env.RESPONSE_MODE || "body").toLowerCase(); // "body", "headers", or "both"
11
12
  const HEADERS_SUCCESS_CODE = parseInt(process.env.HEADERS_SUCCESS_CODE, 10) === 204 ? 204 : 200;
13
+ const DISABLE_UI = process.env.DISABLE_UI === "true" || process.env.DISABLE_UI === "1";
12
14
 
13
15
  // Resolve TLS cert and key: file paths take precedence over inline values
14
16
  let tlsCert;
@@ -45,13 +47,14 @@ const fastify = createApp({
45
47
  apiKey: API_KEY,
46
48
  responseMode: RESPONSE_MODE,
47
49
  headersSuccessCode: HEADERS_SUCCESS_CODE,
50
+ disableUi: DISABLE_UI,
48
51
  fastifyOpts,
49
52
  });
50
53
 
51
54
  // Pre-load the model, then start listening
52
55
  console.log("Loading model (first run downloads ~395M params)...");
53
56
  await detectInjection("warmup");
54
- fastify.listen({ port: PORT, host: "0.0.0.0" }, (err) => {
57
+ fastify.listen({ port: PORT, host: HOST }, (err) => {
55
58
  if (err) { console.error(err); process.exit(1); }
56
59
  const protocol = hasTls ? "https" : "http";
57
60
  console.log(`SaferPrompt running at ${protocol}://localhost:${PORT}`);