comfylib

package module
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: AGPL-3.0 Imports: 0 Imported by: 0

README

comfylib

Shared Go packages for the Comfyware apps, Imvault and Witmoot, plus Songstead.

It holds the security-sensitive plumbing both apps need and should get right once: Bubblewrap confinement, systemd and OpenRC configuration lookup, SMTP sending, key files, tokens, client addresses behind trusted proxies, and reverse-proxy configuration. Application policy, storage schemas, templates and palettes stay in each app. Shared form layout assets and browser assertions keep common screens aligned.

comfylib uses only the Go standard library, so it adds no further modules to either app's dependency tree. It is versioned as v0 while its API settles; each app pins an exact version.

Packages

Package What it does
autobackup Schedules verified private snapshots, prefers zstd with gzip fallback, and bounds archive retention and copy size.
brandimage Bounds and normalizes uploaded PNG, JPEG and GIF branding images.
password Reads confirmed passwords through an app-supplied hidden terminal reader.
clientip Finds the client address behind trusted reverse proxies, groups IPv6 clients by /64 for rate limits, and tells whether the original request used HTTPS.
invitation Describes invitation availability at an explicit time; apps retain atomic redemption and permissions.
ui Embeds shared account and invitation styles, with browser assertions under ui/uitest.
keyfile Loads a key from its own file, creating it atomically on first use, in raw or hex form.
memberprofile Validates optional names, plain-text bios and labeled HTTP/HTTPS links without fetching them. Apps own visibility and storage.
profileimage Bounds account pictures and supplies still and animated renditions.
privdrop Re-runs administrative commands as the service account, refusing to run them as root.
proxyconfig Prints a validated Caddy, nginx or Apache site configuration from an app's own examples.
proxyconfig/proxytest Runs those configurations in real nginx and Apache servers for an app's integration tests.
reference Validates web addresses and prepares explicit browser discussion drafts without networking or automatic posting.
sandbox Confines a service and its child processes with Bubblewrap, and reaps orphans when the service is PID 1.
smtp Sends transactional mail through a relay with required TLS, header-injection checks, and no logging of message bodies.
svcconfig Reads a service's settings, data directory and account the way OpenRC and systemd pass them.
token Mints random tokens, hashes them for storage, and compares them in constant time, and derives session-bound CSRF tokens.

Checks

make check runs formatting, vet, cyclomatic complexity, golangci-lint, the race-enabled tests, the mutation engine's self-test, and every mutation table under mutations/. make test-sandbox needs a working bwrap; make test-proxies needs nginx and Apache; make fuzz-smoke runs every fuzz target briefly. CI runs all of them.

tools/mutate.py applies each mutation in a table to a throwaway copy of the tree and requires the named tests to fail. The apps keep their own tables and a synced copy of the script.

Developing alongside an app

Use a go.work file in the app's worktree rather than a replace directive:

go work init . ../comfylib

go.work is ignored by git. Never commit a replace directive or a go.work file in an app; release builds, the Gentoo ebuilds, and Docker images all resolve comfylib through the Go module proxy.

Licensed under AGPL-3.0-or-later. See LICENSE.

Discussion references (v0.1.1)

reference.URL, reference.Draft, reference.Handoff and reference.Read validate ordinary web addresses and prepare an explicit Witmoot browser draft. Songstead and Imvault use the same URL and text limits; Witmoot validates the handoff again and requires its normal posting flow. No networking, tokens, service discovery or plugin machinery is added. Do not put private notes or private album metadata in a handoff. The exported API golden records the additive package. v0.1.1 is published and used by Songstead, Witmoot and Imvault.

The same release adds token.SessionCSRF(session, purpose). It preserves the existing Witmoot and Imvault HMAC-SHA256 outputs for their application purpose strings and rejects empty inputs. No existing exported API is removed, and the library still uses only the Go standard library.

Shared administration helpers (v0.1.2)

password.Confirm handles two labeled password prompts and propagates reader and writer failures without printing secrets. Applications keep terminal echo control and their own password strength policy.

brandimage.Normalize accepts PNG, JPEG and GIF uploads up to 2 MiB and 2048 by 2048 pixels. It validates dimensions before decoding and emits one PNG, preserving transparency while removing animation and metadata. Songstead, Imvault and Witmoot use the same normalization policy.

profileimage.Normalize adds an account-picture policy: 2 MiB encoded input, 512 by 512 pixels, at most 64 GIF frames, and 4 MiB per output rendition. It re-encodes a GIF animation and a PNG still for viewer motion preferences; compressed frame counts and dimensions are checked before animation decoding.

password.WithHiddenInput disables Linux terminal echo before the first prompt is displayed and keeps it disabled through confirmation. It restores the original terminal state on success, failure and panic, without changing other terminal flags. Wrap the entire Confirm call with it when using a terminal password reader.

Shared invitation and account UI (v0.1.7)

ui.Assets() exposes a read-only filesystem containing accounts.css. Serve it from /static/comfyware/ and load /static/comfyware/accounts.css after the application stylesheet. The styles preserve each application's palette through CSS custom properties and align account forms, invitation controls and responsive records. Templates, application routes and content remain application-owned.

invitation.State.Status(now) describes open, revoked, expired and used-up invitations. Revocation wins over expiry, and expiry wins over exhausted uses. Expiry includes the exact deadline; a nil expiry means never and a nonpositive maximum means unlimited. Status.Label() supplies a sentence-case label. This is a display helper; redemption still needs each app's permission checks and atomic storage transaction.

Browser suites resolve this exact pinned Go module with go list -m -f '{{.Dir}}' github.com/airencracken/comfylib. Import ui/uitest/layout.mjs for driver-neutral DOM checks or ui/uitest/invitations.mjs for the Playwright invitation flow. The Playwright caller supplies path, revokePath, app and optional screenshots; the helper adds no Playwright dependency. CDP callers evaluate the same serialized DOM functions. The default matrix covers 320, 390, 768 and 1280 pixels, both color schemes and JavaScript enabled and disabled. Browser helpers are excluded from ui.Assets().

make test-ui requires Node and runs the helper unit tests plus actual mutations of width limits, overflow checks, control height, contrast, breakpoints and structure. make check includes it. The Go module still uses only the standard library.

Documentation

Overview

Package comfylib holds the code Imvault and Witmoot share: service confinement, service configuration, mail sending, key files, tokens, client addresses behind proxies, reverse-proxy configuration, and automatic backups. Each subpackage uses only the standard library and never imports application code.

Directories

Path Synopsis
Package autobackup schedules private compressed snapshots.
Package autobackup schedules private compressed snapshots.
Package brandimage validates small uploaded PNG, JPEG and GIF images and converts them to a single PNG without metadata or animation.
Package brandimage validates small uploaded PNG, JPEG and GIF images and converts them to a single PNG without metadata or animation.
Package clientip finds the address of the person behind a request, believing forwarding headers only from proxies the operator named.
Package clientip finds the address of the person behind a request, believing forwarding headers only from proxies the operator named.
Package invitation describes invitation availability for display.
Package invitation describes invitation availability for display.
Package keyfile keeps a random key in a file of its own, creating it on first use.
Package keyfile keeps a random key in a file of its own, creating it on first use.
Package memberprofile validates optional, plain-text member biographies and links.
Package memberprofile validates optional, plain-text member biographies and links.
oidc module
Package password provides confirmed password prompting.
Package password provides confirmed password prompting.
Package privdrop re-runs an administrative command as the installed service's account when an operator starts it as root, for example with sudo.
Package privdrop re-runs an administrative command as the installed service's account when an operator starts it as root, for example with sudo.
Package profileimage normalizes account pictures and keeps a still rendition alongside bounded GIF animation.
Package profileimage normalizes account pictures and keeps a still rendition alongside bounded GIF animation.
Package proxyconfig prints a reverse-proxy site configuration for an app, generated from the example files the app ships in its packages.
Package proxyconfig prints a reverse-proxy site configuration for an app, generated from the example files the app ships in its packages.
proxytest
Package proxytest runs an app's generated nginx and Apache configurations in real servers and checks what reaches the app through them.
Package proxytest runs an app's generated nginx and Apache configurations in real servers and checks what reaches the app through them.
Package reference provides browser-only Comfyware discussion handoffs.
Package reference provides browser-only Comfyware discussion handoffs.
Package sandbox constructs explicit Bubblewrap policies.
Package sandbox constructs explicit Bubblewrap policies.
Package smtp sends the small number of transactional messages the apps need, such as password reset links, through an SMTP relay.
Package smtp sends the small number of transactional messages the apps need, such as password reset links, through an SMTP relay.
Package svcconfig reads an installed service's settings the way its service manager would pass them, so that a command an operator runs by hand acts on the same instance as the running service.
Package svcconfig reads an installed service's settings the way its service manager would pass them, so that a command an operator runs by hand acts on the same instance as the running service.
Package token mints opaque secrets and hashes them for storage.
Package token mints opaque secrets and hashes them for storage.
Package ui supplies shared, palette-independent Comfyware presentation assets.
Package ui supplies shared, palette-independent Comfyware presentation assets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL