Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(mcp-studio): stop the bare 'cp' term accusing ordinary prompts of child sexual content

nirholasb428bb95930c
diff --git a/api/_mcp-studio/safety.js b/api/_mcp-studio/safety.js
index 50e49cedc..233430551 100644
--- a/api/_mcp-studio/safety.js
+++ b/api/_mcp-studio/safety.js
@@ -38,9 +38,18 @@ const SEXUAL_TERMS = [
];
// Child-sexual content — zero tolerance; refuse outright.
+//
+// Every term here must be unambiguous, because this category refuses with the
+// blunt "not allowed" message and accuses the caller of the highest-harm
+// request there is. The bare abbreviation "cp" is deliberately NOT in this list:
+// as a whole word it fires on ordinary modeling prompts ("a CP/M retro computer
+// terminal", "a CP violation physics diagram"), and a false accusation of child
+// sexual content is a worse failure than missing an abbreviation nobody types
+// into a 3D generator. The spelled-out forms below cover the real intent.
const CSAM_TERMS = [
- 'loli', 'lolicon', 'shota', 'shotacon', 'cp', 'underage', 'preteen',
- 'pre-teen', 'jailbait', 'child porn', 'childporn', 'minor sex',
+ 'loli', 'lolicon', 'shota', 'shotacon', 'toddlercon', 'underage', 'preteen',
+ 'pre-teen', 'jailbait', 'child porn', 'childporn', 'child sex', 'child sexual',
+ 'minor sex', 'csam',
];
// Graphic violence / gore — keep the asset library age-appropriate.
diff --git a/tests/api/mcp-studio-safety.test.js b/tests/api/mcp-studio-safety.test.js
new file mode 100644
index 000000000..ecad10446
--- /dev/null
+++ b/tests/api/mcp-studio-safety.test.js
@@ -0,0 +1,102 @@
+// Tests for api/_mcp-studio/safety.js, the content gate that every free 3D
+// Studio generation path runs BEFORE any provider work (api/_mcp-studio/tools.js
+// calls it on forge_free, text_to_avatar, mesh_forge, forge_avatar and
+// refine_model; api/3d/studio.js calls it on the REST lane).
+//
+// The gate is a synchronous whole-word keyword classifier, so its two failure
+// modes are the ones worth pinning:
+// 1. FALSE NEGATIVE: a harmful prompt slips through to a provider.
+// 2. FALSE POSITIVE: an ordinary modeling prompt is refused, and in the csam
+// category is refused with an accusation. The whole-word matching exists
+// precisely to stop substring collisions ("assassin" is not "ass").
+
+import { describe, it, expect } from 'vitest';
+import { checkPromptSafety } from '../../api/_mcp-studio/safety.js';
+
+describe('checkPromptSafety allow path', () => {
+ it('lets ordinary creative modeling prompts through', () => {
+ const prompts = [
+ 'a cute robot with round eyes',
+ 'a low-poly mountain landscape',
+ 'a knight with a sword and shield',
+ 'a wizard holding a glowing wand',
+ 'a vintage racing car',
+ 'a ceramic teapot on a wooden table',
+ ];
+ for (const p of prompts) {
+ expect(checkPromptSafety(p), p).toEqual({ allowed: true });
+ }
+ });
+
+ it('treats empty, blank, and missing prompts as allowed (validation is the caller job)', () => {
+ expect(checkPromptSafety('')).toEqual({ allowed: true });
+ expect(checkPromptSafety(' ')).toEqual({ allowed: true });
+ expect(checkPromptSafety(null)).toEqual({ allowed: true });
+ expect(checkPromptSafety(undefined)).toEqual({ allowed: true });
+ });
+});
+
+describe('checkPromptSafety refusal path', () => {
+ it('refuses each harmful category with its own message and the matched term', () => {
+ const cases = [
+ { prompt: 'a nude woman statue', category: 'sexual' },
+ { prompt: 'a decapitated head with gore', category: 'gore' },
+ { prompt: 'a nazi swastika flag', category: 'hate' },
+ { prompt: 'an ar-15 rifle model', category: 'weapon_drug' },
+ { prompt: 'a loli character', category: 'csam' },
+ ];
+ for (const { prompt, category } of cases) {
+ const r = checkPromptSafety(prompt);
+ expect(r.allowed, prompt).toBe(false);
+ expect(r.category, prompt).toBe(category);
+ expect(typeof r.message, prompt).toBe('string');
+ expect(r.message.length, prompt).toBeGreaterThan(0);
+ expect(typeof r.matched, prompt).toBe('string');
+ }
+ });
+
+ it('checks csam first, so the highest-harm category wins a multi-category prompt', () => {
+ expect(checkPromptSafety('underage nude').category).toBe('csam');
+ });
+
+ it('matches case-insensitively and through surrounding punctuation', () => {
+ expect(checkPromptSafety('PORN').allowed).toBe(false);
+ expect(checkPromptSafety('a model, nsfw, please').allowed).toBe(false);
+ });
+});
+
+describe('checkPromptSafety whole-word matching', () => {
+ // The header comment of safety.js promises "assassin" does not trip "ass"
+ // and that "scunthorpe" is safe. These are the prompts that regress if
+ // someone swaps the boundary regex for a plain substring includes().
+ it('does not fire on benign words that merely contain a blocked term', () => {
+ const prompts = [
+ 'an assassin with a hooded cloak',
+ 'a scunthorpe town hall',
+ 'a cumulus cloud',
+ 'a bass guitar',
+ 'a shiitake mushroom',
+ 'a cocktail glass',
+ 'a titmouse bird',
+ 'a grenadier guard in uniform',
+ 'a wooden bureau',
+ ];
+ for (const p of prompts) {
+ expect(checkPromptSafety(p), p).toEqual({ allowed: true });
+ }
+ });
+
+ // Regression: the bare abbreviation "cp" used to sit in CSAM_TERMS, so an
+ // ordinary retro-computing prompt was refused as child sexual content, the
+ // single worst false positive this classifier can produce.
+ it('does not accuse ordinary "cp" prompts of child sexual content', () => {
+ expect(checkPromptSafety('a CP/M retro computer terminal')).toEqual({ allowed: true });
+ expect(checkPromptSafety('a CP violation physics diagram')).toEqual({ allowed: true });
+ });
+
+ it('still refuses the spelled-out child-sexual terms', () => {
+ for (const p of ['child porn', 'childporn art', 'a child sexual image', 'csam', 'jailbait']) {
+ expect(checkPromptSafety(p).category, p).toBe('csam');
+ }
+ });
+});