Webhook icon
Schedule icon
Download icon
Parse icon
Script icon
Switch icon
Write icon
Log icon
If icon
SlackIncomingWebhook icon
Fail icon

Apache Tika Untrusted Document Content Security and Ingestion Gate

Validate untrusted document uploads with Apache Tika, detect MIME spoofing and password locks, and enforce content security before RAG vector indexing.

Categories
Data

Automates pre-ingestion content security, MIME magic-byte verification, and quality triage for untrusted document uploads using Apache Tika. When users or external partners submit documents to enterprise RAG pipelines, search clusters, or compliance archives, downstream embedding models and vector databases face silent corruption or security hazards if files are password-locked, disguise malicious executables, or contain flat scanned bitmaps with zero extractable text. This blueprint evaluates every incoming file with Apache Tika, extracts genuine MIME types and cryptographic flags, classifies the payload into four operational states, and routes clean text to storage while isolating quarantined files with full audit manifests.

How it works

  1. An event-driven Webhook trigger captures incoming document upload events from cloud storage notifications (e.g. S3 or MinIO bucket notifications), while a disabled Schedule provides periodic batch processing capabilities.
  2. download_document (io.kestra.plugin.core.http.Download) streams the incoming file from the source URL or object storage directly into Kestra internal storage (kestra://...).
  3. parse_content_and_metadata (io.kestra.plugin.tika.Parse) auto-detects true document MIME types, cryptographic encryption attributes, page counts, and raw body text using Apache Tika.
  4. evaluate_content_security (io.kestra.plugin.scripts.python.Script) interrogates Tika metadata against operational policies:
    • Checks for MIME masquerading by comparing declared_mime_type against the detected Content-Type magic bytes.
    • Identifies password encryption locks (pdf:encrypted, isEncrypted, hasOwnerPassword) that cause downstream LLM chunking or text extraction workers to crash.
    • Validates text density against min_characters_threshold and page count to isolate ghost scanned images lacking an OCR text layer.
    • Emits typed Kestra metrics and an operational verdict (PASS_CLEAN, QUARANTINE_MIME_SPOOFED, QUARANTINE_ENCRYPTED, or ROUTE_OCR_REQUIRED).
  5. route_security_decision (io.kestra.plugin.core.flow.Switch) executes branch-specific actions based on the classified verdict:
    • PASS_CLEAN: Persists clean extracted text payload to internal storage via io.kestra.plugin.core.storage.Write, ready for zero-copy vectorization.
    • QUARANTINE_MIME_SPOOFED: Writes a security quarantine manifest, logs a high-severity alert, and conditionally dispatches a Slack webhook notification.
    • QUARANTINE_ENCRYPTED: Creates a password hold manifest so client applications can re-submit with credentials.
    • ROUTE_OCR_REQUIRED: Emits an OCR dispatch work order with storage URIs for secondary OCR workers.
  6. enforce_ingestion_gate (io.kestra.plugin.core.flow.If) evaluates quarantine_on_failure. If enabled and the document was not clean, it logs a policy rejection and triggers io.kestra.plugin.core.execution.Fail to alert monitoring systems.

What you get

  • Automated MIME magic-byte verification protecting downstream embedding models and parsers from disguised executables, scripts, or polyglot files.
  • Early detection of password-protected documents, preventing silent null-vector indexing and worker thread freezes.
  • Intelligent ghost-scan triage that diverts bitmap-only PDFs to OCR pipelines instead of poisoning vector stores with empty embeddings.
  • Structured JSON audit manifests and Kestra metrics logging character count, page count, and routing decisions.
  • Clean text extraction stored directly in Kestra internal storage for zero-copy handoff to vector database loaders.

Who it's for

  • AI and ML Platform Engineers building RAG pipelines who need to protect vector databases from corrupted or malicious document uploads.
  • Data Platform Engineers handling multi-tenant document ingestion from untrusted external sources.
  • Security and Compliance Operations teams requiring document sanitation, metadata scrubbing, and quarantine audit trails.

Why orchestrate this with Kestra

  • Seamless chaining of Apache Tika's native Java parser with containerized security verification and multi-path flow control in a single declarative YAML workflow.
  • Ephemeral internal storage management (kestra://...) that avoids saving sensitive or untrusted documents to persistent disk across pipeline steps.
  • Built-in auditability, execution history, and stateful triggers (Webhook and Schedule) that replace brittle custom ingest microservices.

Prerequisites

  • Docker daemon or container runner available to Kestra for executing the python evaluation task.
  • Network connectivity to download document payloads or access internal object storage endpoints.

Secrets

  • TIKA_INGESTION_WEBHOOK_KEY: Secret authentication key for securing the incoming upload Webhook trigger.
  • SLACK_WEBHOOK_URL: Optional Slack incoming webhook URL for dispatching quarantine alerts (required only if notify_slack is enabled).

Quick start

  1. Import this blueprint into your Kestra instance.
  2. Click Execute using the default public sample PDF (app_store.pdf) to verify clean parsing and pass-through routing.
  3. Test failure branches by overriding declared_mime_type (e.g. setting declared_mime_type to application/vnd.openxmlformats-officedocument.wordprocessingml.document with a PDF file) or adjusting min_characters_threshold to observe automated quarantine and routing behavior.
  4. Activate the on_document_upload webhook trigger to connect your upstream upload service.

How to extend

  • Connect downstream vector database upsert tasks (e.g. io.kestra.plugin.qdrant.Upsert, io.kestra.plugin.weaviate.BatchCreate, or Pinecone) in the PASS_CLEAN branch using the staged text URI.
  • Add Tesseract OCR execution via Kestra shell tasks in the ROUTE_OCR_REQUIRED branch to extract text from scanned images on-the-fly.
  • Wire PagerDuty or incident management workflows into the QUARANTINE_MIME_SPOOFED branch to alert SecOps on intentional file masquerading.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.