# 🔐 Security Policy **Current Version: 1.1.0** ### Admin UI is Development-Only **The Admin UI should never be exposed in production environments**. It is designed exclusively for: - **Local development** on developer workstations - **Localhost-only access** with trusted MCP servers - **Single-user administration** without access controls For production deployments: - **Disable features not used by your application**: use feature flags to disable unused features (ex: roots, resources, prompts) as per [537](https://github.com/IBM/mcp-context-forge/issues/537) - **Disable the Admin UI and APIs completely** (`MCPGATEWAY_UI_ENABLED=false` and `MCPGATEWAY_ADMIN_API_ENABLED=false` in `.env`) - **Use only the REST API** with proper authentication - **Build your own production-grade UI** with appropriate security controls ### 🚀 Deployment Recommendations * **Disable unused features** using environment variables and feature flags (`MCPGATEWAY_ENABLE_PROMPTS=false`, etc.) as per [537](https://github.com/IBM/mcp-context-forge/issues/537) * **Use the REST API only**, with strict input validation and authentication * **Disable Admin UI and Admin API** in production (`MCPGATEWAY_UI_ENABLED=false`, `MCPGATEWAY_ADMIN_API_ENABLED=false`) * **Run containers as non-root users**, with read-only filesystems and minimal base images * **Harden network access** with firewalls, ingress policies, and internal-only endpoints * **Set resource limits** (CPU, memory) to protect against denial-of-service risks * **Always deploy the latest version** – there are **no backported security patches or long-term support branches** * **Perform a security audit of the codebase yourself**, especially if deploying in regulated, multi-tenant, or production environments * **Integrate as part of a comprehensive solution**: ContextForge is **not a standalone product**. It is designed to be one layer in a larger, secure system architecture. You should integrate it with complementary components such as: * API gateways or reverse proxies (for auth, rate-limiting, and routing) * Secrets and configuration management systems (e.g., Vault, SOPS) * Identity and access management (IAM) platforms * Logging, monitoring, and alerting tools * Runtime security, anomaly detection, and SIEM platforms * Additional UI or orchestration layers that provide tenant or team-level access controls Always consider your full deployment context and threat model when using ContextForge as part of a broader system. #### 🔐 Environment Variable Security * **Avoid storing secrets in environment variables** unless managed via a secure secrets manager * **Never log environment variables or sensitive configs** * **Restrict container permissions** so only the application process can read environment variables * **Use `.env` files cautiously**, and avoid committing them to version control * **Limit runtime shell access** to containers to prevent environment leaks --- ### Multi-Tenancy Considerations Please review https://ibm.github.io/mcp-context-forge/architecture/multitenancy/ ### General Beta Limitations - **Expect breaking changes** between minor versions - **Validate all MCP servers** before connecting them to the gateway - **Monitor security advisories** closely - **Test thoroughly** in isolated environments before deployment - **Review the codebase** to understand current capabilities and limitations ## Multi-layered Defense Strategy ContextForge project implements a comprehensive, multi-layered security approach designed to protect against vulnerabilities at every stage of the development lifecycle. Our security strategy is built on the principle of "defense in depth," and "secure by design", incorporating Static Application Security Testing (SAST), Dynamic Application Security Testing (DAST), Software Composition Analysis (SCA), Interactive Application Security Testing (IAST), fuzz testing, mutation testing, chaos engineering, mandatory code reviews and continuous monitoring to ensure the highest security standards. ### Security Philosophy As a gateway service that handles Model Context Protocol (MCP) communications and potentially sensitive data flows, security is paramount to our design philosophy. We recognize that modern software security requires proactive measures rather than reactive responses - an a "secure by design" mindset. Our approach combines industry-standard security practices, and secure "defaults" with automated tooling to create a robust security posture. Here's an expanded section for that part: **Tools are not enough**: While our automated security tooling provides comprehensive coverage, we recognize that true security requires human expertise and collaborative oversight. Our security posture extends beyond automated scanning to include: - **Manual Security Code Reviews**: Expert security engineers conduct thorough code reviews focusing on logic flaws, business logic vulnerabilities, and complex attack vectors that automated tools might miss - **Threat Modeling & Risk Assessment**: Regular security assessments evaluate our attack surface, identify potential threat vectors, and validate our defense mechanisms against real-world attack scenarios - **Community-Driven Security**: We actively engage with the security research community, maintain responsible disclosure processes, and leverage collective intelligence to identify and address emerging threats - **Security Champion Program**: Developers across the project receive security training and act as security advocates within their teams, creating a culture of security awareness - **Penetration Testing**: Regular security assessments - **Security Architecture Review**: All major design decisions undergo security architecture review to ensure security considerations are embedded from the earliest stages. This human-centered approach ensures that security is not just a technical implementation detail, but a fundamental aspect of how we design, build, and maintain ContextForge service. ### Comprehensive Security Pipeline Our security pipeline operates at multiple levels: **Pre-commit Security Gates**: Before any code reaches our repository, it must pass through rigorous pre-commit hooks that include multiple security scanners like Bandit for common security issues, Semgrep for semantic pattern matching, Dodgy for hardcoded secrets detection, and detect-private-key for catching committed private keys, along with type checking and code quality enforcement. Pre-commit hooks also enforce **AI content integrity** (preventing AI-generated artifacts such as hallucinated citations, stock phrases, and malformed code fences) and **Unicode safety** (fixing smart quotes, ligatures, and forbidding BiDi control characters to prevent [trojan-source attacks](https://trojansource.codes/)). Developers can run `make security-all` or `make pre-commit bandit semgrep dodgy lint` locally to execute these same security checks before pushing code. **Continuous Integration Security**: Our GitHub Actions workflows implement automated security scanning on every pull request and commit, with **40+ security scans** triggering automatically on every PR, including Semgrep for semantic analysis, detect-secrets for secret detection with baseline allowlist, comprehensive dependency vulnerability scanning with pip-audit, npm audit, and cargo audit, SBOM generation, and Hadolint-style linting where configured, IaC scanning with Checkov and kube-linter, GitHub Actions security linting with Zizmor, and multi-language static analysis across Python, Go, Rust, Shell, and JavaScript. **Code Review Security**: All code changes undergo mandatory peer review with security-focused review criteria, ensuring that security considerations are evaluated by human experts in addition to automated tooling. **Supply Chain Security**: We maintain strict oversight of our software supply chain through automated dependency vulnerability scanning, Software Bill of Materials (SBOM) generation, and license compliance checking to ensure all components meet security standards. Dependency vulnerability findings are surfaced via Dependabot and regularly reviewed and addressed by contributors. Snyk custom rules enforce detection of hardcoded JWT secrets and basic auth credentials (CWE-798). License policies explicitly deny strong-copyleft licenses (GPL-3.0, AGPL-3.0, SSPL) and flag licenses requiring review (MPL-2.0, LGPL-2.0, CC-BY-SA-4.0). **Container Security Hardening**: Our containerized deployments follow security best practices including multi-stage builds, minimal base images (UBI Micro) with the latest updates, non-root user execution, read-only filesystems, and SBOM-based review with complementary dependency and OS/package analysis where configured. **Runtime Security Monitoring**: Beyond build-time security, we implement runtime monitoring and security policies to detect and respond to potential threats in production environments. ### Automated Security Toolchain Our security toolchain includes **40+ different security and quality tools**, each serving a specific purpose in our defense strategy and executed on every pull request: - **Static Analysis Security Testing (SAST)**: CodeQL, Bandit, Semgrep, DevSkim (Microsoft security anti-patterns), and multiple type checkers - **Secret Detection**: detect-secrets with baseline allowlist for tracked-file scanning and pre-commit enforcement, Dodgy for hardcoded secrets in code, detect-private-key for committed private keys, and Snyk custom rules for hardcoded JWT secrets and credentials (CWE-798) - **Dependency Vulnerability Scanning**: OSV-Scanner, pip-audit, npm audit, cargo audit (Rust), govulncheck (Go), and GitHub dependency review with license policy enforcement - **Container Security**: Dockerfile linting, SBOM generation, and Dockle where used - **Infrastructure as Code (IaC) Security**: Checkov for IaC security scanning (Dockerfiles, Helm charts, docker-compose), kube-linter for Kubernetes/Helm manifest best practices - **CI/CD Pipeline Security**: Zizmor for GitHub Actions workflow security linting, actionlint for workflow syntax validation - **Go Security**: gosec for Go static security analysis, golangci-lint with security rules, govulncheck for Go vulnerability database checking - **Rust Security**: cargo audit for Rust dependency vulnerability scanning, cargo clippy for Rust linting - **Shell Security**: shellcheck for shell script security and correctness linting - **Web & Frontend Security**: ESLint, HTMLHint, Biome (CSS), retire.js for known-vulnerable JS library detection, nodejsscan for JavaScript/Node.js security vulnerability scanning, npm audit for package vulnerabilities - **Code Quality & Best Practices**: Interrogate for docstring coverage - **Code Modernization**: pyupgrade for syntax modernization to latest Python versions - **AI Content Integrity**: Pre-commit hooks preventing AI-generated artifacts (hallucinated citations, stock phrases, placeholder references, malformed code fences) - **Unicode & Trojan-Source Prevention**: texthooks for fixing smart quotes and ligatures, forbidding BiDi control characters to prevent [trojan-source attacks](https://trojansource.codes/) - **Documentation Security**: Spellcheck, markdown validation, and detect-secrets to prevent information disclosure - **Security Testing**: Playwright browser-driven security end-to-end tests, diff-cover enforcing appropriate coverage on changed lines in PRs ### Developer Experience & Security We believe that security should enhance rather than hinder the development process. Our comprehensive `make` targets provide developers with easy access to the full security suite, allowing them to run the same checks locally that will be executed in CI/CD: **Core Security Commands**: - `make security-all` - Run all security tools in one command - `make security-report` - Generate comprehensive security report - `make security-fix` - Auto-fix security issues where possible **Individual Security Tools**: - `make pre-commit` - Run all pre-commit hooks locally (includes security scanning) - `make lint` - Comprehensive linting and security checking (40+ tools) - `make test` - Full test suite with coverage analysis and security validation - `make bandit` - Security scanner for Python code vulnerabilities - `make semgrep` - Advanced semantic code analysis for security patterns - `make dodgy` - Detect hardcoded passwords, API keys, and secrets - `make devskim` - DevSkim security anti-pattern detection (Microsoft) - `make detect-secrets-scan` - Regenerate `.secrets.baseline` by scanning files changed vs `main` (override with `GIT_DIFF_TARGET` or `DETECT_SECRETS_PATH`); a jq merge preserves audited entries for out-of-scope tracked files, and the target exits non-zero if the audit report shows any live, unaudited, or audited-as-real findings - `make detect-secrets-audit` - Manually attest to detected secrets being or not being actual secrets - `make detect-secrets-hook` - Locally execute the equivalent command that the pre-commit hook will run - `make interrogate` - Ensure comprehensive docstring coverage - `make pyupgrade` - Modernize Python syntax for security improvements - `make pip-audit` - Python dependency vulnerability scanning - `make security-scan` - Show current local container review guidance - `make dockle` - Container security and best practices analysis - `make hadolint` - Dockerfile linting for security issues - `make osv-scan` - Open Source Vulnerability database scanning - `make sbom` - Software Bill of Materials generation and vulnerability assessment - `make lint-web` - Frontend security validation (HTML, CSS, JS, retire.js, nodejsscan, npm audit) - `make nodejsscan` - Run nodejsscan for JS security vulnerabilities **IaC, CI/CD & Multi-Language Security**: - `make linting-security-checkov` - Checkov IaC security scanning - `make linting-security-kube-linter` - Kubernetes/Helm manifest best-practice linting - `make linting-workflow-zizmor` - GitHub Actions workflow security linting - `make linting-workflow-actionlint` - GitHub Actions workflow syntax validation - `make linting-go-gosec` - Go security static analysis - `make linting-go-govulncheck` - Go vulnerability database checking - `make shell-lint` - Shell script linting with shellcheck **Local-First Security**: Developers are encouraged to run `make pre-commit` and `make test` before every commit, ensuring that security issues are caught and resolved locally before code reaches the repository. This "shift-left" approach means security problems are identified early in the development process, reducing the time and cost of remediation. **CI/CD Security Enforcement**: Even with local testing, our CI/CD pipeline runs the complete security suite on every pull request, with 40+ security scans executed automatically across Python, Go, Rust, Shell, JavaScript, IaC, and container targets. This dual-layer approach ensures no security issues slip through, while the local tooling provides rapid feedback to developers. This approach ensures that security is integrated into daily development workflows rather than being an afterthought, while maintaining the aggressive response timelines our users expect. ### Continuous Improvement Our security posture is continuously evolving. We regularly update our toolchain, review new security practices, and incorporate feedback from the security community. The comprehensive nature of our pipeline means that security vulnerabilities are caught early and addressed promptly, maintaining the integrity of ContextForge service. --- ## 🛡️ Data Validation and Secure Defaults ### Input Validation Framework As of version 0.3.1, ContextForge implements comprehensive input validation across all API endpoints using the [`SecurityValidator`](mcpgateway/common/validators.py:287) class with strict validation rules: - **Character restrictions** for names and identifiers to prevent injection attacks - **URL scheme validation** blocking potentially dangerous protocols (`javascript:`, `data:`, `vbscript:`) - **JSON nesting depth limits** to prevent resource exhaustion attacks - **Field-specific length limits** to ensure predictable resource usage - **MIME type validation** for content type security These validation rules help prevent XSS injection when data from untrusted MCP servers is displayed in downstream UIs. However, **the gateway is only one layer of defense** - downstream applications should implement their own validation and sanitization appropriate to their specific use cases. ### Cross-Site Scripting (XSS) Protection ContextForge implements enterprise-grade XSS protection through the [`SecurityValidator`](mcpgateway/common/validators.py:287) class: **HTML Sanitization:** - [`sanitize_display_text()`](mcpgateway/common/validators.py:313) - Strips HTML tags and dangerous patterns - Blocks `