Repository navigation
Tags
Tags
Add outline scaling to the tool editor (#258) The tool editor could only change an outline's size one vertex at a time. A Size group in the toolbar now shows the outline's width and height and scales the whole outline when a width or height is typed, or by a percentage that applies once and returns to 100. Scaling is about the vertex-mean centre, the centre rotation uses, so a placed tool keeps its position when a bin re-syncs it. Interior rings scale with the outline. Cutouts move with it but keep their own size. The photo underlay matrix and the Detail slider's base are scaled about the same centre in one history entry, as rotate and flip do. The fields scale on Enter only and discard typed text on blur. A drag snapshots the outline on mousedown, before the blur that mousedown causes, so a scale committed on blur would be overwritten by the drag while the photo matrix and Detail base stayed scaled. NumericInput blurred itself on Escape and the blur committed the typed text, so Escape applied the value it was meant to discard, and Enter committed twice. Enter now commits once and Escape discards. The photo guide gains a section on tall or thick objects: the oversize by edge height and camera distance, and how to correct it with the Size fields. Closes #105 Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
fix(docker): install current Pillow and torch dependencies in the ima… …ge (#239) The image installs torch and torchvision from the PyTorch CPU index first. That step also took their dependencies from the CPU index, which carries Pillow 12.3.0 at most, and the later requirements install left the satisfied Pillow in place. Images therefore shipped Pillow 12.3.0 even after Pillow 13.0.0 fixed a large set of decoder vulnerabilities, and filelock and setuptools lagged in the same way. Install only torch and torchvision from the CPU index and let the requirements install resolve their dependencies from PyPI. Require Pillow 13.0.0 so existing environments upgrade too. Upgrade pip before installing, since the base image's pip 25.0.1 has known install-time vulnerabilities. Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
test: preserve pocket depth in split ZIP exports (#235) An older split job could leave 17.45 mm ZIP pockets beside a full STL that already contained the new 12 mm pockets. The export lock in #234 prevents that mismatch. Measure both downloads after overlapping bin and session exports, saved depth changes, per-tool overrides and cached generation. Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
fix: keep overhanging tools, detect paper on dark backgrounds, mask e… …very object (#226) * fix: keep overhanging tools, detect paper on dark backgrounds, mask every object Saliency tracers ran on a crop clipped to the paper rect, so a tool overhanging the sheet came back cut flat at the paper edge, and a tool crossing the sheet split the bright region so the crop kept only the larger half and the tracer masked the printed ruling. The crop now merges sheet fragments of the same tone that line up across a tool-sized gap, and grows on any side the mask touches before running again. Gemini does not crop and is unchanged. Paper corner detection blacked out the U2-Net mask before looking for the sheet, but on a dark background the sheet itself is the salient object, so the upload came back with no corners. A mask over 40% of the frame is now ignored and a masked miss retries unmasked. The mask prompt for dimension-accurate Gemini models asked for one tool while the contour tracer emits a polygon per object; it now asks for every object, and prompt choice no longer piggybacks on the alignment set. TRACERS auto-detect behaviour is documented. Finger holes were rebuilt with hand-written argument lists at six sites, so a field survived only where someone remembered it. Rebuilds now go through model_copy or ScaledFingerHole.from_finger_hole, a test walks FingerHole.model_fields, and the never-called drawer_service module is removed. Closes #212 Closes #213 Closes #223 Closes #214 Signed-off-by: Jason Madigan <jason@jasonmadigan.com> * fix: damp saliency crop growth and pin the fragment gap A grown crop shows more background, which can flip saliency onto the sheet; that mask touches every edge and would have won unconditionally. A grown attempt whose foreground exceeds four times the previous one now loses to the previous crop. The fragment merge gap is fixed to the largest fragment's long side so chained merges cannot walk across the frame. Contour points are cast to int32 before drawContours. A library hole not yet on a placement keeps the library depth_override on sync. README says the grown crop reaches remote providers as extra requests. Signed-off-by: Jason Madigan <jason@jasonmadigan.com> --------- Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
fix(auth): refuse a namespace claim onto an occupied directory (#209) * fix(auth): refuse a namespace claim onto an occupied directory claim() returned early for any namespace without a deletion marker, so the refusal that protects a namespace still holding files only covered namespaces something had explicitly marked. an unmarked directory holding files was claimed silently. POST /api/admin/users takes a caller-supplied id, makes it the account's storage namespace, and ensure_user_dirs adopts an existing tree without touching it, so an account created on a colliding id opened onto another account's files. a marker is the wrong condition: an account creation interrupted before its record landed, or a volume restored without its users.json, leaves occupied directories and no marker at all. refuse on the state of the directory instead. an empty or absent namespace stays claimable, which is the ordinary case. adoption survives only where it is the caller's purpose: first-run setup taking a single-user library into authenticated use, create-admin, and an import that passes adopt_existing_storage. a marked namespace is refused even then, because those files' owner was already destroyed here. the claim still runs before the account is written, so a refusal leaves no account and no directories behind. Closes #208 Signed-off-by: Jason Madigan <jason@jasonmadigan.com> * fix(auth): refuse storage adoption from an admin token review feedback: the adopt_existing_storage field added on this branch was ungated by principal type. get_admin_principal accepts an admin API token, and create_user's only token-specific check covered the admin bit, so a tfadm_ token holder could set one boolean, name any unmarked namespace holding another party's files, create an account onto it and log in as that account to read and write them. reproduced end to end before fixing. extend the invariant the module already holds. a token neither creates an administrator nor writes to an account that is one; now it also cannot open an account onto storage that already holds files. 403 with the same shape as the existing refusal. adoption stays available to an administrator session rather than moving to the CLI. the CLI creates the first administrator only, so this endpoint is the only way to put the second and later accounts back on storage carried over with them, and removing it would push operators to edit users.json by hand. the risk was never that adoption exists, it is that an unattended credential with no password step and no second factor could perform it. checked on the request field rather than on whether the namespace turns out to be occupied, so the answer does not leak which namespaces hold data and there is no window between the check and files arriving. add is_token to AdminPrincipal as the single discriminator both token rules test. token_id is set only by the token branch of get_admin_principal, from a record whose field is a str, so the default None means a session and nothing else; the named property stops a future guard picking the truthiness form instead. Signed-off-by: Jason Madigan <jason@jasonmadigan.com> --------- Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
Add administrator API tokens (#206) * feat(auth): administrator API tokens for the admin API (#205) Administrative endpoints resolved identity only from the login cookie, so a deployment that provisions accounts programmatically had no way in. An automated caller cannot drive a browser login, and cannot supply a second factor at all. `AUTH_SETUP_ENABLED=false` and the `create-admin` command already acknowledge that some installs provision administrators out of band, but both address first run only. An administrator issues an opaque token from a logged-in session and presents it as `Authorization: Bearer`. That header is understood by every HTTP client, a browser never attaches it on its own, and it collides with neither the auth cookie nor `X-Proxy-Secret`. A request carrying a bearer token is decided by that token: an invalid one is 401 and never falls back to a cookie that happens to be present. The token reaches the user-provisioning routes only: list, create, disable, enable and reset password. Clearing a second factor, managing tokens, and instance storage stats stay session-only. A credential that authenticates without a second factor must not be able to remove second factors from accounts, which combined with a password reset would make every account takeable by whoever holds the token; nor mint a successor, because containing a leak should not mean chasing a chain. Routes opt in by declaring `get_admin_principal`, so a route added later reaches nothing until someone says otherwise. Tokens live beside login tokens in auth_tokens.json as sha256 hashes, compared in constant time, each with its own resolver so neither kind is accepted where the other belongs. They do not slide, default to never expiring, take an optional lifetime at issue time, and are revoked individually. A password change no longer takes them with it, since rotating a password is not evidence that a provisioning credential leaked. Disabling or demoting the issuing account makes them inert at once, checked against the live account on every use, and deleting the account destroys them. Every administrative mutation now records who acted and, when a token was used, which token. Only account creation did before. Native mode only: `open` and `proxy` return 404 for this surface as they always have, so nothing here extends `PROXY_SECRET`. Signed-off-by: Jason Madigan <jason@jasonmadigan.com> * fix: stop an admin token reaching administrator authority An administrator API token could set is_admin on POST /api/admin/users, then log in interactively as the account it had just created. That account carries no second factor, so the token holder obtained a full session and with it successor tokens, clear-2fa and storage-stats: every containment decision the credential was built around. Resetting an existing administrator's password reached the same place in one step fewer. A token now neither creates an administrator nor writes to an account that is one. is_admin: true on create is refused with 403, as are reset-password, disable and enable whose target is an administrator, including the account that issued the token. The refusal is explicit rather than a downgrade to a member account: a provisioning script that asked for an administrator and got a 200 would carry on believing it had one. Disable and enable are included because suspending every other administrator locks out the people who could revoke the token, and because the rule is easier to rely on stated once than carved out per route. Ordinary accounts are unaffected, and an administrator session keeps every ability it had. The write guard runs inside the account store lock, against the live record, so it cannot race a change to the target's admin bit. The admin router now declares get_admin_principal as a default dependency, so a route added without an explicit one is authenticated rather than anonymous. FastAPI caches the dependency per request, so the routes that declare it themselves resolve their token once. docs/auth.md claimed a token could not mint another with no chain of successors to chase. That was false as written; it is true now, and the reasoning for each exclusion is recorded alongside it. Relates to #205 Signed-off-by: Jason Madigan <jason@jasonmadigan.com> * fix(auth): reject a trailing newline in an id or namespace Python's `$` matches before a trailing newline, so `_USER_ID_RE` accepted `"<valid id>\n"`. The id becomes a directory name under the storage root, so an admin create, `create-admin --id`, or `--storage-namespace` could land a namespace with a newline in it. That is not cross-user exposure, the namespace is still distinct, but a newline in a path breaks shell globbing, log parsing, backup scripts, and anything that reads a list of namespaces a line at a time. `\A` and `\Z` now anchor the whole alternation rather than each branch, so the cuid and uuid shapes cannot drift apart the way they would if only one side were corrected. `_EMAIL_RE` had the same loose anchor and gets the same treatment; `normalise_email` strips before matching, so no behaviour changes there, but the expression no longer relies on its caller for the guarantee. Nothing legitimate is rejected. Ids come from `uuid4`, the literal "default", or a validated flag or field, and no code builds one from an unstripped line: the only `readline` in the backend is the CLI password prompt, which rstrips, and every store reads whole files as JSON. The one released version carrying this expression, 0.8.0, applies it solely to the proxy `x-user-id` header, where a bare newline cannot cross the wire. Tests cover leading, trailing, and embedded newlines and other trailing whitespace on all four paths through the validator, and on the validator itself. Relates to #205 Signed-off-by: Jason Madigan <jason@jasonmadigan.com> --------- Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
feat(auth): native single-user-first authentication (#204) Tracefinity had no accounts. A standalone install was a single anonymous user, and multi-user deployments relied on a trusted reverse proxy asserting identity through a header, so nothing inside the application knew who anyone was. Add native authentication with three modes. `native` is the default: a fresh install prompts for an initial administrator, there is no default password, and identity comes from a cookie. `proxy` preserves the existing trusted-header behaviour for deployments that use it and is deprecated. `open` keeps the current single-user behaviour for anyone running privately who wants no login at all. Absent identity fails closed in native and proxy; only open retains the anonymous fallback. Accounts live in users.json at the storage root, hashed with stdlib scrypt behind a scheme prefix so other schemes can be verified and transparently upgraded on the next login. Auth tokens are opaque, stored hashed, and revoked on logout, password change, disable and deletion. Isolation is enforced server side: the storage guard resolves identity per mode rather than trusting a path segment, and existing installs keep their data because the first administrator claims the default namespace by alias, so no files move and no stored path is rewritten. Two-factor authentication is included. Enrolment confirms a code before enabling, login becomes a two step exchange through a single-use pending token, verification is stdlib RFC 6238 with replay protection, and secrets are encrypted at rest under a key derived from AUTH_SECRET with rotation support. Backup codes are single use and regenerable, and an administrator can clear a locked-out account's second factor. Accounts can be created with an externally supplied id and credential so an installation migrating from another system keeps its storage keying and its users' existing passwords. The same is available without the web flow: `python -m app.cli create-admin` creates the first administrator from inside a container, for deployments that provision out of band and close the web setup route. It reads the password from a prompt or stdin, never from an argument, and hands anything it creates as root to the storage owner so the service can still read it. Startup now validates the mode against what the volume already holds. Serving an instance that has accounts in a mode with no login would publish the first administrator's data to anyone and strand the rest, so open and proxy refuse to start in that state unless explicitly overridden. A native start with no accounts on populated storage warns that setup is open on data somebody already owns. AUTH_SETUP_ENABLED closes the web setup route entirely for deployments that create administrators by other means. Instance storage statistics previously relied on the proxy secret alone, which is unset in native mode, leaving the per-user roster readable by anyone; that endpoint now requires an administrator and the secret comparison is constant time. Account writes use compare-and-set so a concurrent administrative change cannot be reverted by a slower request, and the store refuses any change that would leave no enabled administrator. Deleting the last administrator while other accounts remain is refused, and a namespace whose deletion did not complete is marked so a later account cannot inherit its files. The generated API documentation is no longer served, and the remaining unauthenticated surface is the health check, the version, and the auth entry points. Closes #197 Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
Show app version in settings popover (#145) * Add version endpoint sourced from image build (#144) Bake APP_VERSION into the Docker image (release tag for releases, dev-<sha> for dev builds, dev locally) and expose it via GET /api/version. Signed-off-by: Jason Madigan <jason@jasonmadigan.com> * Show app version in settings popover (#144) Fetched from /api/version on first open, hidden if the request fails. Signed-off-by: Jason Madigan <jason@jasonmadigan.com> * Smoke test release image version in CI (#144) Fail the release build if the pushed image does not report the release tag, catching a dropped build-arg or non-semver tag. Signed-off-by: Jason Madigan <jason@jasonmadigan.com> * Harden version tests against ambient env (#144) Check the Settings default with APP_VERSION unset rather than via the import-time singleton, and use the fixture style of neighbouring route tests. Signed-off-by: Jason Madigan <jason@jasonmadigan.com> * Make version display optional via SHOW_APP_VERSION (#144) Defaults on. When false, /api/version returns 404 (so the settings popover shows nothing) and the OpenAPI version is a neutral placeholder, disclosing nothing. Signed-off-by: Jason Madigan <jason@jasonmadigan.com> * Smoke test image before pushing release (#144) Build a single-arch image with load, check the baked APP_VERSION against the release tag with a literal compare that logs both values, and only then run the multi-arch push. Stops a bad version reaching the public tags. Signed-off-by: Jason Madigan <jason@jasonmadigan.com> * Ignore empty env vars in settings (#144) An empty value (docker run -e SHOW_APP_VERSION=) crashed settings validation at import; fall back to defaults instead. Tests build fresh Settings without the dotenv file and restore reloaded modules even if the reload itself fails. Signed-off-by: Jason Madigan <jason@jasonmadigan.com> --------- Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
PreviousNext