Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(safety): B3 aus review-w2ui, Cloud-Erwachsenengatter an den echten Aufrufstellen verdrahtet

purpledcb494a6cb0c
diff --git a/src/hooks/__tests__/useCloudCreate-b3-adult-gate-fires-before-upload.test.ts b/src/hooks/__tests__/useCloudCreate-b3-adult-gate-fires-before-upload.test.ts
new file mode 100644
index 00000000..b79f9ada
--- /dev/null
+++ b/src/hooks/__tests__/useCloudCreate-b3-adult-gate-fires-before-upload.test.ts
@@ -0,0 +1,140 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * B3 (review-w2ui.md, 18.09.2026): checkPromptSafety's adult half
+ * (ADULT_SOFT_TERMS/ADULT_HARD_TERMS) only fires with `tier: 'cloud'`, and no
+ * caller ever passed that, making it unreachable. R5-9's own wording is
+ * "damit die Ablehnung vor dem Upload kommt" (so the rejection comes before
+ * the upload), this is the test AT THE CALLER the fixliste line asks for.
+ *
+ * useCloudCreate.generate() and .makeVoice() are exercised end to end (real
+ * createStore, mocked network/catalog layer) with a hardcore adult prompt.
+ * Before the fix, this prompt passed the client gate silently and went on to
+ * call uploadInput/submitCloudJob; after the fix it is refused before either
+ * runs, exactly like uselu's own useCloudCreate.
+ *
+ * Run: npx vitest run src/hooks/__tests__/useCloudCreate-b3-adult-gate-fires-before-upload.test.ts
+ */
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+import { renderHook, act } from '@testing-library/react'
+
+const hoisted = vi.hoisted(() => {
+ class FakeCloudJobError extends Error {
+ status: number
+ code?: string
+ retryAfterMs?: number
+ constructor(message: string, status: number) {
+ super(message)
+ this.status = status
+ }
+ }
+ return {
+ policySnapshot: 'strict' as 'strict' | 'soft' | 'off' | null,
+ submitCloudJob: vi.fn(async () => ({ id: 'job-1' })),
+ uploadInput: vi.fn(async () => 'uploaded/path'),
+ getJob: vi.fn(),
+ cancelJob: vi.fn(async () => ({ status: 'canceled' })),
+ // 'canceled' short-circuits the post-submit result handling in both
+ // generate() and makeVoice() cleanly, this test only cares about what
+ // happens BEFORE submitCloudJob, not the full success path.
+ pollJob: vi.fn(async () => ({ id: 'job-1', status: 'canceled' as const })),
+ FakeCloudJobError,
+ }
+})
+const { submitCloudJob, uploadInput } = hoisted
+
+vi.mock('../useContentPolicy', () => ({
+ contentPolicySnapshot: () => hoisted.policySnapshot,
+ loadContentPolicy: async () => hoisted.policySnapshot ?? 'soft',
+}))
+
+vi.mock('../../api/cloud/jobs', () => ({
+ submitCloudJob: (...a: Parameters<typeof hoisted.submitCloudJob>) => hoisted.submitCloudJob(...a),
+ uploadInput: (...a: Parameters<typeof hoisted.uploadInput>) => hoisted.uploadInput(...a),
+ getJob: (...a: Parameters<typeof hoisted.getJob>) => hoisted.getJob(...a),
+ cancelJob: (...a: Parameters<typeof hoisted.cancelJob>) => hoisted.cancelJob(...a),
+ pollJob: (...a: Parameters<typeof hoisted.pollJob>) => hoisted.pollJob(...a),
+ CloudJobError: hoisted.FakeCloudJobError,
+}))
+
+vi.mock('../../stores/cloudCatalogStore', () => ({
+ defaultCloudModel: () => ({ id: 'test-model' }),
+ modelForOp: () => 'test-model',
+ resolveOpPick: () => 'test-model',
+ cloudModelById: () => undefined,
+ cloudMediaLive: () => true,
+}))
+
+import { useCloudCreate } from '../useCloudCreate'
+import { useCreateStore } from '../../stores/createStore'
+import { blockMessageFor } from '../../lib/render/safety'
+
+beforeEach(() => {
+ submitCloudJob.mockClear()
+ uploadInput.mockClear()
+ hoisted.policySnapshot = 'strict'
+ useCreateStore.setState({
+ prompt: '',
+ negativePrompt: '',
+ musicLyrics: '',
+ triggerWord: '',
+ isGenerating: false,
+ error: null,
+ } as Partial<ReturnType<typeof useCreateStore.getState>>)
+})
+
+describe('B3: useCloudCreate.generate() runs the adult gate before any upload/submit', () => {
+ it('a hardcore adult prompt is refused, uploadInput and submitCloudJob are never called', async () => {
+ useCreateStore.getState().setPrompt('hardcore porn scene')
+ const { result } = renderHook(() => useCloudCreate())
+ await act(async () => {
+ await result.current.generate()
+ })
+ expect(uploadInput).not.toHaveBeenCalled()
+ expect(submitCloudJob).not.toHaveBeenCalled()
+ expect(useCreateStore.getState().error).toBe(blockMessageFor('adult-cloud'))
+ expect(useCreateStore.getState().error).not.toBe(blockMessageFor('csam'))
+ })
+
+ it('the same prompt is NOT blocked once the account policy is "off" (never a guessed rule)', async () => {
+ hoisted.policySnapshot = 'off'
+ useCreateStore.getState().setPrompt('hardcore porn scene')
+ const { result } = renderHook(() => useCloudCreate())
+ await act(async () => {
+ await result.current.generate()
+ })
+ expect(submitCloudJob).toHaveBeenCalledOnce()
+ expect(useCreateStore.getState().error).toBeNull()
+ })
+
+ it('NEGATIVE CONTROL: an ordinary prompt is never blocked and still submits', async () => {
+ useCreateStore.getState().setPrompt('a mountain landscape at sunrise')
+ const { result } = renderHook(() => useCloudCreate())
+ await act(async () => {
+ await result.current.generate()
+ })
+ expect(submitCloudJob).toHaveBeenCalledOnce()
+ expect(useCreateStore.getState().error).toBeNull()
+ })
+
+ it('CSAM still wins the reason even with tier: cloud wired in (never softened to adult-cloud)', async () => {
+ useCreateStore.getState().setPrompt('child porn')
+ const { result } = renderHook(() => useCloudCreate())
+ await act(async () => {
+ await result.current.generate()
+ })
+ expect(submitCloudJob).not.toHaveBeenCalled()
+ expect(useCreateStore.getState().error).toBe(blockMessageFor('csam'))
+ })
+})
+
+describe('B3: useCloudCreate.makeVoice() runs the same gate', () => {
+ it('a hardcore adult voice description is refused before submitCloudJob', async () => {
+ const { result } = renderHook(() => useCloudCreate())
+ await act(async () => {
+ await result.current.makeVoice({ text: 'hardcore porn scene', mode: 'design', description: 'narrator' })
+ })
+ expect(submitCloudJob).not.toHaveBeenCalled()
+ expect(useCreateStore.getState().error).toBe(blockMessageFor('adult-cloud'))
+ })
+})
diff --git a/src/hooks/useCloudCreate.ts b/src/hooks/useCloudCreate.ts
index e618cee8..427f0caa 100644
--- a/src/hooks/useCloudCreate.ts
+++ b/src/hooks/useCloudCreate.ts
@@ -29,10 +29,27 @@ import {
cloudModelById,
cloudMediaLive,
} from '../stores/cloudCatalogStore'
-import { checkPromptSafety, SAFETY_BLOCK_MESSAGE } from '../lib/render/safety'
+import { checkPromptSafety, blockMessageFor, type SafetyVerdict } from '../lib/render/safety'
+import { contentPolicySnapshot, loadContentPolicy } from './useContentPolicy'
import { signalCreditsExhausted } from '../lib/credits-exhausted'
import { resolveRunSeed } from '../lib/run-seed'
+// B3 (review-w2ui.md, 18.09.2026): the CSAM floor above runs regardless of
+// tier, but the adult half of safety.ts (ADULT_SOFT_TERMS/ADULT_HARD_TERMS)
+// only ever fires on tier: 'cloud', which no caller passed until now, making
+// half the module unreachable. R5-9 exists precisely so "the rejection comes
+// before the upload" for the cloud path too, matching uselu's own
+// useCloudCreate (apps/web/hooks/useCloudCreate.ts, clientSafety()).
+//
+// If the account policy has not loaded yet, this checks CSAM only ('off'):
+// never block on a guessed rule, the server is the authority for the rest,
+// same reasoning as uselu's own comment on clientSafety().
+function clientSafety(text: string): SafetyVerdict {
+ const policy = contentPolicySnapshot()
+ if (!policy) void loadContentPolicy() // for the next run
+ return checkPromptSafety(text, { tier: 'cloud', policy: policy ?? 'off' })
+}
+
// Character-Studio generation endpoint per trained-LoRA family (fast default;
// mirrors uselu's LORA_GEN_FAMILY — ltx-2 video characters have no image-gen
// lane and qwen has no -lora generation endpoint yet).
@@ -193,12 +210,17 @@ export function useCloudCreate(opts: { onQuotaChange?: () => void } = {}) {
s.setError('Please enter a prompt.')
return
}
- // Client-side CSAM gate (UX) over every free-text field this run sends.
- // The server additionally enforces its SFW-cloud policy — its 422 message
- // lands in setError below.
- if (checkPromptSafety(`${s.prompt} ${s.negativePrompt} ${s.musicLyrics} ${s.triggerWord}`).blocked) {
- s.setError(SAFETY_BLOCK_MESSAGE)
- return
+ // Client-side CSAM + account-adult-policy gate (UX) over every free-text
+ // field this run sends. The server additionally enforces its own policy
+ // read fresh from the account row, its 422 message lands in setError
+ // below either way; this only saves the round trip when the client
+ // already knows the verdict (B3).
+ {
+ const verdict = clientSafety(`${s.prompt} ${s.negativePrompt} ${s.musicLyrics} ${s.triggerWord}`)
+ if (verdict.blocked) {
+ s.setError(blockMessageFor(verdict.reason))
+ return
+ }
}
// Per-intent input contracts (client UX; the server re-checks all of it).
if (characterUse && !s.selectedCharacter) {
@@ -469,8 +491,9 @@ export function useCloudCreate(opts: { onQuotaChange?: () => void } = {}) {
s.setError('Type what the character should say.')
return
}
- if (checkPromptSafety(`${text} ${opts.description ?? ''}`).blocked) {
- s.setError(SAFETY_BLOCK_MESSAGE)
+ const voiceVerdict = clientSafety(`${text} ${opts.description ?? ''}`)
+ if (voiceVerdict.blocked) {
+ s.setError(blockMessageFor(voiceVerdict.reason))
return
}
s.setError(null)
diff --git a/src/hooks/useContentPolicy.ts b/src/hooks/useContentPolicy.ts
index 4543c52d..d0d4fdac 100644
--- a/src/hooks/useContentPolicy.ts
+++ b/src/hooks/useContentPolicy.ts
@@ -16,7 +16,7 @@ let cached: ContentPolicy | null = null
let inflight: Promise<ContentPolicy> | null = null
const listeners = new Set<(p: ContentPolicy) => void>()
-async function loadContentPolicy(): Promise<ContentPolicy> {
+export async function loadContentPolicy(): Promise<ContentPolicy> {
if (cached) return cached
if (!inflight) {
inflight = getContentPolicy()
@@ -35,6 +35,16 @@ async function loadContentPolicy(): Promise<ContentPolicy> {
return inflight
}
+/**
+ * The policy as currently known, without triggering a fetch. `null` means
+ * "not loaded yet"; a caller that needs to act on it (B3: the client-side
+ * cloud adult gate in useCloudCreate) must treat that as "unknown", not as
+ * a guessed rule, mirroring uselu's contentPolicySnapshot().
+ */
+export function contentPolicySnapshot(): ContentPolicy | null {
+ return cached
+}
+
/** Push a freshly saved policy into the shared cache (call after a
* successful PUT), so every mounted ModelChip picks it up immediately
* instead of waiting for a reload. */