T09 · Insecure Skill Coding Practices
- Location
src/prompt-builder.js:303- Finding
Detected and Unrecognized PII Is Still Transmitted to the External Model
- Content
View full analysis
Vulnerability Details
File Location:
src/validators.js:540-593,src/prompt-builder.js:303-332,src/prompt-builder.js:519-529, andsrc/index.js:218-231
Vulnerability Type: Incomplete PII sanitization and fail-open validation
Risk Level: MediumVulnerable Code
src/validators.js:540-593detects possible personal names in nested team biographies but only generates a warning:js function validatePIISafety(input) { const piiFields = ['contact_name', 'contact_phone']; const warnings = []; if (!input || typeof input !== 'object') { return { piiFields, warnings }; } // Detect possible Chinese real names in team_composition[].background if (Array.isArray(input.team_composition) && input.team_composition.length > 0) { const allBackgrounds = input.team_composition .map((m, idx) => ({ idx, text: m.background || '' })) .filter(item => typeof item.text === 'string' && item.text.trim()); const nameContextPattern = /[\u4e00-\u9fa5]{2,4}(?=是|叫|说|告诉|表示|介绍|反映|名叫|叫做)/g; const nameAfterDelimiter = /[::、,]\s*([\u4e00-\u9fa5]{2,4})(?=[,,。\s]|$)/g; allBackgrounds.forEach(({ idx, text }) => { const matches1 = text.match(nameContextPattern) || []; const matches2 = []; let dm; while ((dm = nameAfterDelimiter.exec(text)) !== null) { matches2.push(dm[1]); } nameAfterDelimiter.lastIndex = 0; const matches = [...matches1, ...matches2]; if (matches && matches.length > 0) { const uniqueMatches = [...new Set(matches)]; warnings.push( `team_composition[${idx}].background 中检测到疑似真实姓名:${uniqueMatches.join('、')}。请使用职位/专业背景描述代替真实姓名(如"社会工作专业硕士"),以保护团队成员隐私。`, ); } }); } return { piiFields, warnings }; }src/prompt-builder.js:303-332removes only two exact top-level fields. All other values, including nested values and free-text content, are copied into the model prompt:js function buildUserPromp ...[truncated 4857 chars]- Remediation
View remediation
Remediation Suggestions
-
Create a sanitized data object before prompt construction
- Never pass the original
inputtobuildPrompt(). - Make validation return a separately constructed, sanitized object.
- Ensure all downstream model operations use only that object.
- Never pass the original
-
Use an explicit schema allowlist
- Reconstruct only the fields required for each application type.
- Reject or discard unknown properties.
- Define permitted nested keys for arrays such as
team_composition,activities_design, andbudget_breakdown.
-
Apply recursive PII filtering
- Inspect all strings in nested arrays and objects.
- Detect and redact or block phone numbers, identity numbers, email addresses, bank details, physical addresses, and likely personal names.
- Apply special handling to beneficiary narratives and team biographies.
-
Fail closed for high-confidence PII
- Convert high-confidence findings from warnings into blocking validation errors.
- Require the user to remove individual-level data before any external model request.
- Enforce the documented restriction on individual-level data concerning children under 14.
-
Minimize transmitted data
- Send only fields needed for the requested template or regenerated section.
- For section regeneration, avoid transmitting unrelated sections and unrelated input fields.
-
Retain gateway filtering as defense in depth
- Continue using model-gateway filtering, but do not rely on it as the sole privacy control.
- Verify that the gateway rejects rather than merely logs high-confidence PII.
-
Add regression tests
- Assert that nested names, telephone numbers, identity numbers, addresses, bank details, and beneficiary-level data never appear in generated model messages.
- Test unknown keys and deeply nested objects.
- Test both full generation and section regeneration paths.
-
