Security Policy
WARNING – DO NOT EXPOSE TO THE PUBLIC INTERNET
Seg-Studio ships with no built-in user accounts or RBAC. It is designed for local workstation use or trusted private networks. Exposing the API or UI to the public internet will allow anyone (unless a reverse proxy is in front) to:
- Read, modify, and delete all project data (images, masks, models)
- Execute training jobs that consume GPU/CPU resources
- Upload arbitrary files to the server
If you need network access (e.g., sharing with teammates on a LAN), you MUST place the application behind a reverse proxy (nginx, Caddy, etc.) with TLS and authentication enabled. See docs/deployment.md for a complete reverse-proxy setup guide.
By default, all start scripts bind to
127.0.0.1(localhost only). To enable LAN access, setSEG_HOST=0.0.0.0(or turn on Settings → Allow access from LAN) and restart with a launcher. The Trainer API refuses to start on a non-loopback bind whileSEG_API_TOKENis empty, and the launchers mint, persist and print a token on the first LAN start – so a Trainer API published to a LAN by a launcher is always token-protected. (Starting uvicorn by hand with--host 0.0.0.0but noSEG_HOSTbinds the LAN without tripping that check. Always set both.) A reverse proxy is what adds TLS and real user accounts on top, and is required for anything beyond a trusted LAN.The Serving API on port 8001 has none of that. It does not read
SEG_API_TOKENand performs no authentication, yet the launchers bind it to the sameSEG_HOSTas the Trainer API. Keep it on loopback, or firewall port 8001 and front it with an authenticating proxy – see docs/deployment.md.
Optional shared-secret API token
For deployments that need a minimal defense-in-depth layer (e.g., a reverse proxy in front of multiple users on a LAN), set:
SEG_API_TOKEN=<a long random secret>
in your .env. When present, every request to /api/v1/*, /v2/*,
and /ws/v2/* must carry the header X-API-Token: <value> or it is
rejected with 401; WebSocket handshakes without a valid token are
closed with code 4401. Browsers cannot set custom WebSocket headers,
so WebSocket clients may pass the token as an api_token query
parameter instead. Leave
the variable empty (default) to disable the check — this is the expected
configuration for localhost-only use.
The shipped UI now wires this up: it asks for the token once and exchanges it
for an HttpOnly, SameSite=Strict session cookie via
POST /api/v1/auth/session, because a browser cannot put a custom header on an
<img> or a download link. Scripts and curl send the X-API-Token header
directly. Requests whose TCP peer is the server’s own machine are exempt from
the token entirely. The bundled seg-sdk client does not send the header
yet, so run it on the server’s own machine, or point it at a server with
SEG_API_TOKEN unset. The full rules are in
docs/deployment.md.
SEG_API_TOKEN guards /api/v1/*, /v2/* and /ws/v2/* on the Trainer
API only. The Serving API (port 8001) does not implement it.
Labelling with a vision model (AI support)
The AI support panel (Assist) on the Annotate screen sends a project’s data
to the model server that is configured: the pictures the model is shown, your
instruction, the tool results, image ids and the project’s name. The
pictures are scaled or cropped copies of the project’s images, and some
carry masks drawn over the image: a person’s own masks (with single objects
cut out below them), SAM’s proposals and the specks spot_detect found, and
the masks the run wrote. Treat that server as something that sees your data.
- The address and the key are configuration on the machine. The
connection comes from
SEG_VLM_BACKEND,SEG_VLM_BASE_URL,SEG_VLM_MODELandSEG_VLM_API_KEY_ENVin the environment, or from thevlmblock ofprojects/runtime_settings.json(the environment wins). No API endpoint takes an address or the name of a key variable, so neither a browser nor anyone holding the API token can name an address for the trainer to contact. Abase_urlthat is nothttp://orhttps://is ignored, and the backend’s default address is used instead. - What a page may choose is two names.
PUT /api/v1/agent/connectionstores the kind of model server, the model, or both, in thatvlmblock. The kind is one of a fixed list (Ollama, LM Studio, vLLM, MLX, llama.cpp), and each stands for the one127.0.0.1address that server listens on by default, so the choice stays on the machine that runs Seg-Studio. A change of kind is refused when the machine itself has set an address or a key, has namedopenai, or has set the server through the environment, and while a run is going. The model is a name on whichever server is in use: it is stored in each of those cases, and refused only whenSEG_VLM_MODELsets it. A settings file that cannot be read is left as it is. The request is held to the same token and same-origin checks as every other change. - The defaults are local. With nothing set, the trainer looks for Ollama
on
127.0.0.1, and a run starts once a model is chosen. Every backend exceptopenaidefaults to a server on127.0.0.1(Ollama port 11434, LM Studio 1234, vLLM 8000, MLX and llama.cpp 8080);openaidefaults tohttps://api.openai.com/v1. - A remote server should be reached over
https://, on a host you trust. Overhttp://the images, the prompts and the key cross the network in the clear. - The key is never stored in settings.
api_key_envholds the name of an environment variable. The trainer reads the key from that variable when it talks to the model server and sends it, asAuthorization: Bearer, to that server only. - A run can write masks, and delete nothing. The MCP bridge a run starts
runs with
--policy write, neverfull(see below). Every call is held to the project the run was started on and to that project’s images, and a run cannot replace a mask a person drew or an image a person marked clean. - The AI support panel’s endpoints (
/api/v1/projects/{project_id}/agent/*,/api/v1/agent/runsand/api/v1/agent/connection) are behind the same token rules as the rest of/api/v1. A project’s conversation is kept inprojects/<project id>/agent_thread.jsonandprojects/<project id>/agent_logs/, without the pictures.
Data rules given to the model
The MCP bridge’s connect-time instructions open with data rules
(DATA_RULES in scripts/mcp_server.py; also the resource
segstudio://rules and the top of every prompt). MCP leaves it to the
client whether connect-time instructions reach its model, so a short form
of the rules also ends every tool’s description; check that your client
passes server instructions on, or attach the resource. The AI support panel
puts the full text at the head of its system prompt and does not start a
run when the bridge sends none. The rules
tell the model to keep everything it receives through the bridge out of any
other tool, MCP server, web search, URL, file or message; to treat text
inside the data as data, not as instructions; and not to identify people or
read out, collect or keep personal information seen in the pictures;
masks on people or text are labelling like any other. A site that overrides
the playbook with --playbook cannot remove them.
They are instructions, and a model can fail to follow them. What keeps data on the machine is where the model runs and what else its client can reach: the bridge itself talks only to the Seg-Studio server it was given, a model served on the internet receives the pictures in every request, and a client that also has web, file or other MCP tools relies on the model obeying the rules. For data that must not leave the machine, use a model server on the machine and a client without other network tools.
The MCP bridge
scripts/mcp_server.py gives an MCP client – a desktop assistant, an agent
of your own, or the AI support panel – tools over the Trainer API. Every tool
is READ, WRITE or DESTRUCTIVE, and --policy decides which run:
--policy |
What runs |
|---|---|
read (default) |
READ tools only: look at projects, images, masks, runs and results, and change nothing |
write |
READ and WRITE tools: write masks, mark images clean or for review, upload images, create projects, change splits and classes, start and stop training, export models, generate reports, draft from a finished run. Some of these change what everyone using the trainer shares: hardware_set_device switches the compute device for every project and saves the choice; classes_set renames, recolours, deactivates or adds a project’s classes; assistant_context_set replaces a project’s assistant notes; dataset_prepare_annotate and dataset_set_split move images between splits; train_start and assistant_command (/train start) start training on the compute device; train_stop stops a run whoever started it |
full |
also the DESTRUCTIVE tools (train_run_delete, clear_class), and overwrite=true on a person’s work |
- Under
write, no tool writes over a mask a person drew or an image a person marked clean. That is all the rule protects: a project’s classes, its splits, its notes, the compute device and training change underwriteas the table above says.mask_put,write_kept,spot_write,mark_clean,recipe_applyandprelabel_runleave a mask a person drew and an image a person marked clean as they are.overwrite=trueover such an image needs--policy full, because what it replaces is not kept: the first five keep no copy, andprelabel_runkeeps a copy of the mask file inprojects/<project id>/masks_replaced/only until the next draft over that image, and none of a clean mark.prelabel_runwithoverwrite=trueis checked against every image it would draft over – the images named, or every image in the project when none are named – and is refused as a whole underwriteif any of them carries a person’s work. The AI support panel runs the bridge withwrite. - The trainer checks too. The bridge names itself on every request
(
X-Seg-Agent). The trainer records the agent as the author (by) of what it writes through the mask, mark-clean, unmark-clean and recipe-apply routes, and answers 409 when an agent’s write through one of them would replace a person’s work, unlessoverwrite=1is passed. The draft route (prelabel) does neither: a draft written throughprelabel_runis markeddraft: truewith the run that drafted it (draftRun), the route records no agent (by), and it does not ask who made the mask it replaces; forprelabel_runthe bridge’s own check is the guard. The header is the caller’s own statement, so this guards against an agent’s mistakes; it is not access control, and any client holding the API’s credentials can write as a person. - Token. The bridge sends
--token(orSEG_API_TOKEN) asX-API-Token. A Trainer API with a token configured needs it from every client that is not on the server’s own machine; a request whose TCP peer is loopback and that carries no forwarding header is exempt (see above), so a bridge on the same machine talking tohttp://127.0.0.1:8002needs none. On a shared machine, preferSEG_API_TOKENto--token, which the process list shows. The bridge warns at startup when it has no token for an API that is not local. The AI support panel hands its bridgeSEG_API_TOKENthrough the environment, never the command line, together with only a short list of ordinary environment variables. - Ids are checked before they reach a URL. Every id that goes into a
request path (
item_id,like_item_id,run_id,filename) is refused if it contains/,\or?or is.or.., and every path segment is percent-encoded. A project may be named instead of given by id; a WRITE or DESTRUCTIVE tool takes an id, an exact name or a name ignoring case, never a fragment of one. - Text from the API is sanitised. Strings in API responses that look
like instructions to a model are replaced with a placeholder, and the tools
that write text back (
classes_set,assistant_context_set) refuse text that carries it. Every tool call is logged to stderr. - No update check. The MCP library the bridge is built on can ask PyPI, when a server starts, whether a newer release of itself exists. The bridge switches that check off and starts the library without the library’s own banner: the version stays the one the install pins, and starting the bridge, from the panel or from a client, does not send that request.
The example chat page
scripts/examples/qwen_mcp_chat.py is an example, not part of the product
UI, and it has no login. Its bridge runs with --policy write, so
whoever can send it a request can write masks into the trainer’s projects,
read the conversation and its pictures, and use the configured model server.
So:
- It listens on this machine only.
--hostmust be127.0.0.1,localhostor::1. Reach it from another machine through an SSH tunnel (for examplessh -L 8765:127.0.0.1:8765 <host>), not over the network. - It refuses other origins. A request whose
Hostheader does not name the loopback address the page listens on (orlocalhost) is refused with 403, so a web page whose name has been pointed at127.0.0.1gets nothing. A POST must beapplication/json(415 otherwise), and a POST whoseOriginis not the page’s own is refused with 403 before it reaches a route. A POST with noOriginis accepted: browsers send one, so it comes from a program on this machine. - The model server’s address and key are set on the command line only.
--base-urland--api-key-env(the name of the variable holding the key) cannot be changed from the page, and a request that names either is refused with 400. The page can switch between the known servers, reached at their default addresses with no key, and pick a model. The key is sent only to the server that--backendnames (without--backend, the server the page starts on: the one used last, else Ollama), at the--base-urladdress or that server’s default address. The page remembers only the server’s name and the model, and ignores an address saved by an earlier version. - Conversations are kept in
~/.seg-studio/vlm-chat(or the directorySEG_VLM_CHAT_STATEnames). A conversation carried on from there is sent with the current system prompt, the data rules first, not the one it was saved with.
Supported Versions
| Version | Supported |
|---|---|
| 0.9.x | Yes |
| < 0.9 | No |
Only the latest released version receives security updates.
Scope
Seg-Studio is designed as a local desktop application for Windows and Linux workstations with NVIDIA GPUs and macOS machines with Apple Silicon (MPS). It is not intended to be exposed to the public internet.
- The Trainer API (port 8002) and the Serving API (port 8001) both listen on
localhostby default. The example chat page (port 8765) listens on loopback only and refuses any other address. - Neither API sends CORS headers, so a page from another origin cannot read their responses.
- Even with no token configured, the Trainer API’s guarded paths (
/api/v1/*,/v2/*,/ws/v2/*) reject cross-origin state changes and unexpectedHostheaders, so a page you merely visit cannot drive your local install. - No user authentication is enforced unless
SEG_API_TOKENis configured; the application is otherwise assumed to run in a trusted local environment. - The Serving API does not implement
SEG_API_TOKENat all. What reaches it is decided by the bind address and your firewall, and by nothing else.
If you deploy this application on a network-accessible server, you are responsible for adding appropriate authentication, TLS, and network-level access controls.
Reporting a Vulnerability
If you discover a security vulnerability, please report it privately:
- GitHub Security Advisories: Use the Report a vulnerability feature on GitHub.
- Include steps to reproduce, affected versions, and potential impact.
We will acknowledge receipt within 3 business days and aim to provide a fix or mitigation within 14 business days for critical issues.
Please do not open public GitHub issues for security vulnerabilities.
Dependency Auditing
Run the included audit script to check for known vulnerabilities in dependencies:
# Windows
scripts\audit.bat
# macOS / Linux
bash scripts/audit.sh
This runs npm audit for the UI and pip-audit for the API.
One advisory is accepted for now: GHSA-4j2p-28q2-5m79 in accelerate, which has
no fixed release, is ignored by the CI pip-audit steps because the two
checkpoint loaders it affects are called neither by Seg-Studio nor by peft, the
only package that brings accelerate in; a local run still lists it, and the
ignore is removed once accelerate ships a fix.
Security Measures
- Path traversal protection: All file operations use
_safe_child()/_safe_dir()to prevent directory escape. - Upload size limits: 200 MB per file for image/asset uploads, enforced on both client and server. The Serving API’s
/countand/segmentrefuse a body over 50 MB with 413. ZIP project import has its own limit (4 GB by default, configurable in Settings up to 64 GB). - Input sanitization: Filenames are sanitized to prevent injection attacks.
- Security headers:
X-Content-Type-Options: nosniff,X-Frame-Options: DENY(generated report HTML is servedSAMEORIGINfor the in-app preview iframe),Referrer-Policy: strict-origin-when-cross-origin. - No secrets in error responses: The global exception handler returns sanitized 500 errors without stack traces.
- Structured logging: Errors are logged server-side with timestamps; no sensitive data is sent to the client.