Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
# Copy to .env. Add real values only to the ignored .env file.
# Optional: local mode works without an env file or service accounts.
COMIC_CODE_MODE=local
NEXT_PUBLIC_APP_URL=http://127.0.0.1:3000
WXT_PUBLIC_API_BASE_URL=http://127.0.0.1:3000

NEXT_PUBLIC_APP_URL=http://localhost:3000
WXT_PUBLIC_API_BASE_URL=http://localhost:3000
# Optional server-side GitHub token for a higher public API request limit.
# Never use a NEXT_PUBLIC_ or WXT_PUBLIC_ prefix for this token.
GITHUB_TOKEN=

TRIGGER_SECRET_KEY=
TRIGGER_PROJECT_REF=

GITHUB_APP_ID=
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GITHUB_PRIVATE_KEY_BASE64=
GITHUB_WEBHOOK_SECRET=
GITHUB_APP_SLUG=

NEXT_PUBLIC_SUPABASE_URL=
SUPABASE_SECRET_KEY=

SHARE_TOKEN_PEPPER=
SAFETY_IDENTIFIER_SECRET=
SESSION_ENCRYPTION_SECRET=
CRON_SECRET=
# Optional absolute directory on a persistent local disk.
# COMIC_CODE_DATA_DIR=/absolute/path/to/comic-data
27 changes: 27 additions & 0 deletions .env.hosted.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
COMIC_CODE_MODE=hosted

# Copy to .env. Add real values only to the ignored .env file.

NEXT_PUBLIC_APP_URL=http://localhost:3000
WXT_PUBLIC_API_BASE_URL=http://localhost:3000

TRIGGER_SECRET_KEY=
TRIGGER_PROJECT_REF=

GITHUB_APP_ID=
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GITHUB_PRIVATE_KEY_BASE64=
GITHUB_WEBHOOK_SECRET=
# Hosted extension OAuth recipients. Comma-separated IDs from chrome://extensions.
# Empty permits web login only. Local mode never needs OAuth or this setting.
ALLOWED_EXTENSION_IDS=
GITHUB_APP_SLUG=

NEXT_PUBLIC_SUPABASE_URL=
SUPABASE_SECRET_KEY=

SHARE_TOKEN_PEPPER=
SAFETY_IDENTIFIER_SECRET=
SESSION_ENCRYPTION_SECRET=
CRON_SECRET=
42 changes: 42 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
push:
branches: [main]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
verify:
name: Tests, builds, and dependency audit
runs-on: ubuntu-latest
timeout-minutes: 20
env:
WXT_PUBLIC_API_BASE_URL: https://comic-code-ci.example
steps:
- name: Check out source
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 11.11.0
- name: Install locked dependencies
run: pnpm install --frozen-lockfile
- name: Run tests, lint, formatting, production builds and typechecks
run: pnpm check
- name: Package Chrome extension
run: pnpm extension:zip
- name: Audit runtime and development dependencies
run: pnpm audit
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Local secrets
.env
.env.local
.env.production
.env.*.local
*.pem

Expand All @@ -24,3 +25,9 @@ test-results/
.DS_Store
coverage/
.vercel

# Single-user local comics (never commit generated content)
.comic-code/
# Built browser preview mirrors the extension output; regenerated by the build.
apps/web/public/extension-preview/
.impeccable/review/
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ pnpm-lock.yaml
apps/web/next-env.d.ts
.env.example
supabase/migrations/*.sql

apps/web/public/extension-preview
328 changes: 147 additions & 181 deletions README.md

Large diffs are not rendered by default.

56 changes: 46 additions & 10 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
# Security policy
# Security

## Local runtime

The default runtime is a single-user desktop service. It accepts public GitHub
repositories only, with no OAuth session or remote database. Its proxy and API
handler reject non-loopback hosts and origins. Mutations require a same-port
loopback origin or a Chrome extension origin; bearer strings do not bypass this
check. This trusts locally installed browser extensions and local processes.
It is not an authentication boundary against another user on the same computer.
Use `pnpm dev` or `next start --hostname 127.0.0.1`; do not expose it through a
tunnel or reverse proxy. Vercel defaults to hosted mode and requires the hosted
credentials. The `/api/local` handler returns 404 in hosted mode.

Local persistence contains sanitized analysis, evidence locators and PNG bytes,
never source or provider credentials. Writes replace complete records atomically
using owner-only file permissions. One server process per data directory is
supported, with one mutation at a time. Expired records are removed lazily on
read/list, including their PNG bytes. Local deletion removes the complete file.
Downloaded copies cannot be revoked. Online capability sharing is unavailable
in local mode. See the README for storage and generation limits.

## Hosted runtime

## Scope

Comic Code handles private source code and treats pull-request titles, descriptions, paths, patches, and generated model output as untrusted.
Comic Code handles private source code and treats repository names, descriptions, README content, manifests, paths, source, and generated model output as untrusted.

## Implemented controls

- OAuth state and PKCE with a ten-minute encrypted flow cookie.
- Authenticated/encrypted seven-hour session JWE; browser cookies are HttpOnly, SameSite Lax, and Secure in production.
- Bearer sessions returned to the extension only in the `chromiumapp.org` URL fragment.
- Read-only GitHub permissions and separate user-access plus installation-access checks for private repositories.
- Server verification of repository, PR number, selected paths, and captured head SHA.
- Server verification of repository access, requested ref, and captured immutable commit SHA.
- Exclusion of `.env`, credentials, lockfiles, binary, generated, vendored, minified, and oversized reconstructed files.
- Secret/token/email/connection-string masking plus high-entropy masking.
- Prompt-injection boundaries, strict Zod structured output, no model tools, and opaque safety identifiers.
Expand All @@ -20,27 +42,32 @@ Comic Code handles private source code and treats pull-request titles, descripti
- Forced RLS and no anon/authenticated table grants.
- Tombstone-first deletion, worker tombstone checks, artifact cleanup, Trigger.dev cancellation, and daily retention.
- CSP, frame denial, HSTS, no-sniff, restrictive permissions policy, CSRF origin checks, webhook HMAC verification, quotas, and bounded request bodies.
- Cloudflare BYOK credentials accepted only on authenticated, same-origin analysis/artwork requests; strict Account ID/token bounds; provider errors reduced to safe codes; credentials excluded from persistence, Trigger.dev, analytics, and audit metadata.
- BYOK source context is secret-masked, bounded, and sent to Cloudflare only after an explicit user action; model output passes strict schema, grounding, leak, and safety validation.
- Image BYOK requests require the existing local-origin or hosted authentication/ownership/repository-access checks. Provider/model/key combinations are validated strictly; only fixed official OpenAI and Gemini endpoints are used, with redirects disabled. Keys are excluded from persistence, Trigger.dev, analytics and audit metadata.
- Image BYOK sends only sanitized illustration prompts from the saved storyboard, after an explicit generation action. No raw source or evidence bodies are sent. JSON responses, base64 data, raster signatures and decoded pixels are bounded; remote image URLs are never followed. Provider response/error bodies are never logged or returned to clients.
- BYOK artwork uploaded under a new random object path and swapped only after successful composition; failed regeneration preserves prior comic.

## Data that is persisted

Repository/PR coordinates, captured SHAs, selected/excluded file paths, evidence line locators and hashes, sanitized claims/storyboard text, generated PNG paths, usage counts, progress, and low-cardinality audit metadata.
Repository coordinates, captured ref and commit SHA, scan summary, selected/excluded file paths, evidence line locators and hashes, sanitized claims/storyboard text, generated PNG paths, usage counts, progress, and low-cardinality audit metadata.

Raw patches, source blobs, prompt bodies containing source, GitHub access tokens, OAuth codes, share tokens, and provider request bodies are not persisted.

Cloudflare Account IDs and API tokens are not persisted by Comic Code. Web values remain in tab memory. Extension values remain in `chrome.storage.local` on the user's device until removed. API tokens and masked selected code context cross the Comic Code server transiently over HTTPS for Cloudflare Llama and FLUX calls. Tokens must be dedicated and scoped only to Workers AI.
OpenAI and Gemini image keys remain in webpage tab or extension panel memory;
they are not saved in Chrome storage. They cross the Comic Code server
transiently and authenticate only with the selected provider. Hosted traffic
uses HTTPS; local traffic stays on loopback. The extension removes obsolete
saved Cloudflare credentials during initialization. Gemini Interactions calls
set `store: false`; provider-specific data policies still apply.

## Residual considerations

- Cloudflare receives the masked source context in BYOK mode under the user's Cloudflare account and applicable Cloudflare data-usage terms; Comic Code does not present that path as Zero Data Retention.
- The selected image provider receives illustration prompts under the user's account and applicable provider data policies. Image generation does not verify the storyboard's claims or guarantee text-free artwork.
- A revoked share may retain an already minted signed asset URL for at most five minutes.
- The encrypted extension session is still a bearer capability and expires after seven hours. Chrome extension storage must be treated as sensitive.
- Public-repository fallback uses unauthenticated GitHub API capacity and may be rate limited.
- Chrome, not the extension, controls left/right side-panel placement.
- A local extension credential can be read by Comic Code extension code and anyone controlling that Chrome profile. Users should create a dedicated least-privilege Workers AI token and revoke it if the device or extension becomes untrusted.
- A complete live review must test the deployed GitHub, Supabase, Trigger.dev, Cloudflare BYOK, and Vercel configuration with real credentials.
- Keys in tab/panel memory can be read by someone controlling that page or device. Use a dedicated provider key with suitable account limits and revoke it if compromised.
- A complete live review must test the deployed GitHub, Supabase, Trigger.dev, OpenAI/Gemini BYOK, and Vercel configuration with real credentials.

## Dependency status

Expand All @@ -49,3 +76,12 @@ On 2026-07-20, `pnpm audit --prod` reported no known vulnerabilities after scope
## Reporting

Do not include private source, secrets, tokens, or full request logs in a report. Revoke affected credentials first, then provide a minimal reproduction through the repository’s private security-reporting channel.

## Manual artwork

The shared browser artwork studio accepts PNG/JPEG/WebP files up to 8 MB each,
checks decoded images against a 40-megapixel limit, and composes four or twelve
panels on a local Canvas. It makes no upload or AI-provider requests. Object URLs
are revoked when artwork changes or the component closes. Manual artwork is not
added to persisted comics or shared artifacts. The extension browser preview
permits blob images while keeping API connections blocked.
5 changes: 0 additions & 5 deletions apps/extension/entrypoints/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ export default defineBackground(() => {
comicCodeCoordinate: message.coordinate,
})

void chrome.sidePanel.setOptions({
tabId: sender.tab.id,
path: 'sidepanel.html',
enabled: true,
})
void chrome.sidePanel.open({ tabId: sender.tab.id })
})

Expand Down
37 changes: 15 additions & 22 deletions apps/extension/entrypoints/github.content.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
const pullRequestPath = /^\/([^/]+)\/([^/]+)\/pull\/(\d+)(?:\/|$)/
import { parseGitHubRepositoryUrl } from '@comic-code/contracts/repository-url'

function readCoordinate() {
const match = window.location.pathname.match(pullRequestPath)
if (!match) return null

const pullRequestNumber = Number(match[3])
if (!Number.isSafeInteger(pullRequestNumber) || pullRequestNumber < 1) {
return null
}

return {
owner: match[1]!,
repository: match[2]!,
pullRequestNumber,
}
return parseGitHubRepositoryUrl(window.location.href)
}

function mountExplainButton() {
Expand All @@ -26,14 +14,13 @@ function mountExplainButton() {
existing?.remove()
return
}

if (existing) return

const button = document.createElement('button')
button.type = 'button'
button.dataset.comicCodeTrigger = 'true'
button.className = 'Button--primary Button--medium Button'
button.textContent = 'Explain PR'
button.textContent = 'Explain Repository'
button.addEventListener('click', () => {
void chrome.runtime.sendMessage({
type: 'comic-code:open-sidepanel',
Expand All @@ -42,10 +29,9 @@ function mountExplainButton() {
})

const target =
document.querySelector('.gh-header-actions') ??
document.querySelector('[data-testid="pull-request-header"]') ??
document.querySelector('[data-testid="repository-overview"]') ??
document.querySelector('.file-navigation') ??
document.querySelector('main')

target?.prepend(button)
}

Expand All @@ -54,15 +40,22 @@ export default defineContentScript({
runAt: 'document_idle',
main() {
let currentHref = window.location.href
mountExplainButton()

const observer = new MutationObserver(() => {
let scheduled = false
const refresh = () => {
scheduled = false
if (window.location.href !== currentHref) {
currentHref = window.location.href
document.querySelector('[data-comic-code-trigger]')?.remove()
}
mountExplainButton()
}
const observer = new MutationObserver(() => {
if (scheduled) return
scheduled = true
window.requestAnimationFrame(refresh)
})

refresh()
observer.observe(document.documentElement, {
childList: true,
subtree: true,
Expand Down
15 changes: 15 additions & 0 deletions apps/extension/entrypoints/sidepanel/bootstrap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import { createRoot } from 'react-dom/client'
import { SidePanelShell } from './main'

const root = document.getElementById('root')

if (!root) {
throw new Error('Missing Comic Code side-panel root')
}

createRoot(root).render(
<React.StrictMode>
<SidePanelShell />
</React.StrictMode>,
)
2 changes: 1 addition & 1 deletion apps/extension/entrypoints/sidepanel/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="./main.tsx"></script>
<script type="module" src="./bootstrap.tsx"></script>
</body>
</html>
Loading
Loading