Skip to content

feat: Add configurable CSP image domains via environment variable#1278

Open
yang1002378395-cmyk wants to merge 3 commits intokhoj-ai:masterfrom
yang1002378395-cmyk:feat/csp-env-config
Open

feat: Add configurable CSP image domains via environment variable#1278
yang1002378395-cmyk wants to merge 3 commits intokhoj-ai:masterfrom
yang1002378395-cmyk:feat/csp-env-config

Conversation

@yang1002378395-cmyk
Copy link
Copy Markdown
Contributor

Summary

This PR adds support for configuring Content-Security-Policy (CSP) image domains via environment variables, addressing the need for users to load images from custom domains (e.g., CDN, external image hosts).

Changes

  1. Frontend (Next.js): Added NEXT_PUBLIC_CSP_IMG_DOMAINS environment variable support in layoutHelper.tsx
  2. Backend (Python): Added CSPHeadersMiddleware to pass domains via X-Khoj-CSP-Img-Domains header
  3. Documentation: Added example in docker-compose.yml for the new KHOJ_CSP_IMG_DOMAINS env var

Usage

Build-time (Docker build)

NEXT_PUBLIC_CSP_IMG_DOMAINS=static.example.com,cdn.example.com

Runtime (Docker run)

environment:
  - KHOJ_CSP_IMG_DOMAINS=static.example.com,cdn.example.com

Testing

  • Python syntax check passed
  • Manual testing with custom image domains

Fixes #1249

🤖 Generated with Claude Code

阳虎 added 3 commits March 15, 2026 00:36
When ChatModel.friendly_name is None, __str__ returns None causing:
TypeError: __str__ returned non-string (type NoneType)

Fixed by falling back to name field when friendly_name is None.
…loading model

When SearchModelConfig.ApiType.LOCAL is set with an embeddings_inference_endpoint,
Khoj was still downloading the model from HuggingFace instead of using the API.

Changes:
- Only load SentenceTransformer locally when ApiType.LOCAL and no endpoint configured
- Use OpenAI-compatible API for local endpoints (llama.cpp, vLLM, etc.)
- Handle None API key for local servers that don't require authentication

Fixes khoj-ai#1253
- Add NEXT_PUBLIC_CSP_IMG_DOMAINS env var for build-time configuration
- Add KHOJ_CSP_IMG_DOMAINS env var for runtime hint
- Add CSPHeadersMiddleware to pass domains via X-Khoj-CSP-Img-Domains header
- Document new env var in docker-compose.yml

Fixes khoj-ai#1249
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.

csp (content security policy) allow external static image server

1 participant