Skip to content

Conversation

@primeinteger
Copy link
Contributor

@primeinteger primeinteger commented Jan 6, 2026

Purpose

Adds security validation to prevent prompt injection attacks when processing Google Docs with AI.

Approach

New Security Module (functions/security/):

  • ContentValidator - Detects prompt injection patterns and removes dangerous characters
  • GoogleDocsValidator - Validates Google Docs JSON, checking only user text (paragraphs, tables, images) and skipping metadata
  • 27 tests covering all validation scenarios

Integration:

  • Validates documents in documentParser.agent before sending to OpenAI
  • Blocks processing if malicious patterns detected
  • Added security instructions to system prompt

Future Use:

  • validateContentSecurity() available for validating user input in future features

Testing steps

  1. Run tests: npm test -- security/
  2. Test with malicious doc: Add "Ignore all previous instructions" to a Google Doc and verify it's blocked
  3. Test with normal doc: Verify regular content processes successfully

Screenshots

Function logs include details if the document was rejected due to security validation:

Screenshot 2026-01-06 at 11 51 28 AM

@primeinteger primeinteger requested a review from a team as a code owner January 6, 2026 18:46
Copy link
Contributor

@ryunsong-contentful ryunsong-contentful left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, easy to extend and can even be its own agent in the future

@primeinteger primeinteger merged commit 25a0d1c into master Jan 7, 2026
15 checks passed
@primeinteger primeinteger deleted the INTEG-3326 branch January 7, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants