Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

ci(platform): keep the OSS Scanner's build and threat model in .oss-scanner/ (#15360)

Nicholas Tindlef8ffdc9d9187
diff --git a/.oss-scanner/Dockerfile b/.oss-scanner/Dockerfile
new file mode 100644
index 0000000000..d9eccdf426
--- /dev/null
+++ b/.oss-scanner/Dockerfile
@@ -0,0 +1,369 @@
+# syntax=docker/dockerfile:1
+#
+# AutoGPT Platform (https://github.com/Significant-Gravitas/AutoGPT), built for Anthropic's OSS Scanner. The scanner
+# builds `dev` with this file, then scans the result offline, reading threat_model.md (its enrolment is
+# projects/autogpt in https://github.com/anthropics/oss-scanner). A change to how the platform builds or runs its
+# tests should update this file in the same pull request.
+#
+# This builds autogpt_platform/ the way its maintainers and CI do:
+# - the FastAPI backend and its services (REST, WebSocket, executor, scheduler, AutoPilot) and the shared
+# autogpt_libs package: Python 3.13, Poetry and the generated Prisma client
+# - the Next.js frontend, which also hosts the Better Auth service: Node, pnpm and a production build
+# classic/ is unsupported legacy code and is not installed (see threat_model.md).
+#
+# CI runs the backend tests against PostgreSQL 15 with pgvector, a 3-shard Redis cluster, RabbitMQ and ClamAV,
+# each in a container of its own. This image has them all installed instead, with a database already migrated to
+# the checkout:
+#
+# autogpt-services start PostgreSQL :5432, Redis cluster :17000-17002, RabbitMQ :5672, ClamAV :3310
+# . /etc/autogpt-scanner/test.env the environment CI runs the backend tests in
+# cd /src/autogpt_platform/backend && poetry run pytest -q backend/api/features/library
+#
+# threat_model.md also says how to run the whole platform offline.
+
+# RabbitMQ with the Erlang and OpenSSL it is built against, at the version backend CI tests with.
+FROM rabbitmq:4.1.4 AS rabbitmq
+
+FROM debian:trixie
+
+ENV DEBIAN_FRONTEND=noninteractive \
+ LANG=C.UTF-8 \
+ LC_ALL=C.UTF-8 \
+ PYTHONUNBUFFERED=1 \
+ POETRY_HOME=/opt/poetry \
+ POETRY_NO_INTERACTION=1 \
+ POETRY_VIRTUALENVS_CREATE=true \
+ POETRY_VIRTUALENVS_IN_PROJECT=true \
+ COREPACK_HOME=/opt/corepack \
+ COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \
+ NEXT_TELEMETRY_DISABLED=1 \
+ PGDATA=/var/lib/postgresql/data \
+ ERLANG_INSTALL_PATH_PREFIX=/opt/erlang \
+ OPENSSL_INSTALL_PATH_PREFIX=/opt/openssl \
+ RABBITMQ_HOME=/opt/rabbitmq \
+ RABBITMQ_NODENAME=rabbit@localhost \
+ RABBITMQ_CONFIG_FILE=/etc/rabbitmq/rabbitmq.conf \
+ RABBITMQ_MNESIA_BASE=/var/lib/autogpt-services/rabbitmq \
+ RABBITMQ_LOG_BASE=/var/log/autogpt-services \
+ ERL_EPMD_ADDRESS=127.0.0.1 \
+ PATH=/opt/poetry/bin:/usr/lib/postgresql/15/bin:/opt/rabbitmq/sbin:/opt/erlang/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+
+# Python 3.13 (what the production image runs) and what building wheels needs; PostgreSQL 15 and pgvector from
+# PGDG, the versions CI and production use; Valkey for the Redis cluster; ClamAV, which scans every upload; and
+# the programs the backend's blocks and AutoPilot tools call (ffmpeg, ImageMagick, bubblewrap for the sandboxed
+# shell, ...).
+RUN printf '#!/bin/sh\nexit 101\n' > /usr/sbin/policy-rc.d \
+ && chmod 0755 /usr/sbin/policy-rc.d \
+ && apt-get update \
+ && apt-get install -y --no-install-recommends ca-certificates curl gnupg postgresql-common \
+ && install -d -m 0755 /etc/apt/keyrings \
+ && curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/keyrings/postgresql.gpg \
+ && echo 'deb [signed-by=/etc/apt/keyrings/postgresql.gpg] https://apt.postgresql.org/pub/repos/apt trixie-pgdg main' \
+ > /etc/apt/sources.list.d/pgdg.list \
+ && echo 'create_main_cluster = false' > /etc/postgresql-common/createcluster.conf \
+ && apt-get update \
+ && apt-get install -y --no-install-recommends \
+ build-essential git pkg-config openssl procps psmisc netcat-openbsd less \
+ python3.13 python3.13-dev python3.13-venv \
+ libpq-dev libffi-dev libssl-dev zlib1g-dev \
+ postgresql-15 postgresql-client-15 postgresql-15-pgvector \
+ valkey-server valkey-tools \
+ clamav-daemon clamdscan \
+ ffmpeg imagemagick jq ripgrep tree bubblewrap libatomic1 \
+ && rm -f /usr/sbin/policy-rc.d \
+ && rm -rf /var/lib/apt/lists/*
+
+COPY --from=rabbitmq /opt/erlang /opt/erlang
+COPY --from=rabbitmq /opt/openssl /opt/openssl
+COPY --from=rabbitmq /opt/rabbitmq /opt/rabbitmq
+
+# The expert roster and marketplace skills live in a separate repository. Backend CI checks it out and points
+# SKILLS_CATALOG_PATH at it (test.env does the same), so no test needs the GitHub API.
+RUN git clone --depth 1 https://github.com/Significant-Gravitas/skills-catalog /opt/skills-catalog
+
+# scanner contract: the checkout lives inside the image, at /src. Dockerfile.dockerignore, next to this file, stops
+# the repository's .dockerignore (written for the product images) from leaving parts of the checkout out.
+COPY . /src
+
+# Node at the major version in .nvmrc, and pnpm through corepack.
+RUN node_major="$(tr -dc '0-9.' < /src/.nvmrc | cut -d. -f1)" \
+ && test -n "${node_major}" \
+ && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
+ && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${node_major}.x nodistro main" \
+ > /etc/apt/sources.list.d/nodesource.list \
+ && apt-get update \
+ && apt-get install -y --no-install-recommends nodejs \
+ && rm -rf /var/lib/apt/lists/* \
+ && npm install --global corepack \
+ && corepack enable \
+ && node --version
+
+# The backend: Poetry at the version that wrote poetry.lock (CI does the same) in a venv of its own, then the
+# backend and its dev dependencies (pytest and friends) into autogpt_platform/backend/.venv, and the Prisma client.
+WORKDIR /src/autogpt_platform/backend
+RUN poetry_version="$(sed -n '1s/.*by Poetry \([0-9][0-9.]*\).*/\1/p' poetry.lock)" \
+ && test -n "${poetry_version}" \
+ && python3.13 -m venv /opt/poetry/venv \
+ && /opt/poetry/venv/bin/pip install --no-cache-dir "poetry==${poetry_version}" \
+ && install -d /opt/poetry/bin \
+ && ln -s ../venv/bin/poetry /opt/poetry/bin/poetry \
+ && poetry env use python3.13 \
+ && poetry install --no-ansi \
+ && poetry run prisma generate \
+ && poetry run gen-prisma-stub \
+ && rm -rf /root/.cache/pypoetry \
+ && ln -s /opt/poetry/bin/poetry /usr/local/bin/poetry
+
+# tiktoken downloads its encodings the first time they are used, and the backend uses one as soon as
+# backend/api/features/search/embeddings.py is imported, which most test modules do. Fetch them all now.
+ENV TIKTOKEN_CACHE_DIR=/opt/tiktoken
+RUN poetry run python - <<'EOF'
+import tiktoken
+
+for name in tiktoken.list_encoding_names():
+ try:
+ tiktoken.get_encoding(name)
+ except Exception as error:
+ if name in ("cl100k_base", "o200k_base"):
+ raise
+ print(f"WARNING: tiktoken encoding {name} is not cached: {error}")
+EOF
+
+# The frontend: its pinned pnpm, locked dependencies, the generated API client and a production build. Its .env
+# (gitignored) points the Better Auth service at the local database. pnpm's store (node_modules holds copies of it)
+# and Next's build cache take about 5.5 GB that nothing reads once the build is done.
+WORKDIR /src/autogpt_platform/frontend
+RUN corepack install \
+ && pnpm install --frozen-lockfile \
+ && pnpm run generate:api \
+ && sed -e 's|^DATABASE_URL=.*|DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres|' \
+ -e 's|^AUTH_DB_SCHEMA=.*|AUTH_DB_SCHEMA=public|' \
+ -e "s|^BETTER_AUTH_SECRET=.*|BETTER_AUTH_SECRET=$(openssl rand -hex 32)|" \
+ .env.default > .env \
+ && (NEXT_SKIP_BUILD_CHECKS=true timeout 1500 pnpm build \
+ || echo 'WARNING: next build failed; `pnpm dev` still serves the frontend') \
+ && rm -rf "$(pnpm store path)" .next/cache
+
+COPY --chmod=0755 <<'EOF' /usr/local/bin/autogpt-services
+#!/usr/bin/env bash
+# autogpt-services start|stop|restart|status [postgres] [redis] [rabbitmq] [clamav]
+#
+# The services AutoGPT's backend and its tests use, all on localhost, so they work without a network:
+# postgres PostgreSQL 15 + pgvector on :5432, user postgres (trust auth, any password)
+# redis a 3-shard Redis cluster (Valkey) on :17000-17002, as in CI and production
+# rabbitmq RabbitMQ on :5672, user rabbitmq_user_default (password in /etc/autogpt-scanner/secrets.env)
+# clamav ClamAV on :3310; its only signature is the EICAR test file's
+# Logs are in /var/log/autogpt-services.
+set -euo pipefail
+
+# A login shell's /etc/profile resets PATH, so don't rely on it.
+export PATH="/usr/lib/postgresql/15/bin:/opt/rabbitmq/sbin:/opt/erlang/bin:$PATH"
+. /etc/autogpt-scanner/secrets.env
+
+LOGS=/var/log/autogpt-services
+STATE=/var/lib/autogpt-services
+PG_BIN=/usr/lib/postgresql/15/bin
+REDIS_PORTS=(17000 17001 17002)
+
+mkdir -p "$LOGS" "$STATE"
+
+# wait_for SECONDS WHAT COMMAND...: retry COMMAND once a second until it succeeds.
+wait_for() {
+ local seconds=$1 what=$2
+ shift 2
+ for _ in $(seq "$seconds"); do
+ if "$@" >/dev/null 2>&1; then return 0; fi
+ sleep 1
+ done
+ echo "autogpt-services: $what is not up after ${seconds}s; see $LOGS" >&2
+ return 1
+}
+
+postgres_up() { "$PG_BIN/pg_isready" -h localhost -p 5432 -q; }
+postgres_start() {
+ install -d -o postgres -g postgres -m 2775 /run/postgresql
+ touch "$LOGS/postgres.log" && chown postgres:postgres "$LOGS/postgres.log"
+ postgres_up && return 0
+ runuser -u postgres -- "$PG_BIN/pg_ctl" -D "$PGDATA" -l "$LOGS/postgres.log" -w -t 60 start >/dev/null
+ wait_for 30 PostgreSQL postgres_up
+}
+postgres_stop() {
+ runuser -u postgres -- "$PG_BIN/pg_ctl" -D "$PGDATA" -m fast -w stop >/dev/null 2>&1 || true
+}
+
+redis_up() {
+ local port
+ for port in "${REDIS_PORTS[@]}"; do
+ valkey-cli -p "$port" cluster info 2>/dev/null | grep -q '^cluster_state:ok' || return 1
+ done
+}
+redis_start() {
+ redis_up && return 0
+ redis_stop
+ local port
+ for port in "${REDIS_PORTS[@]}"; do
+ rm -rf "${STATE:?}/valkey/$port" && mkdir -p "$STATE/valkey/$port"
+ valkey-server --port "$port" --bind 127.0.0.1 --daemonize yes \
+ --dir "$STATE/valkey/$port" --logfile "$LOGS/valkey-$port.log" \
+ --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 \
+ --cluster-require-full-coverage no --save '' --appendonly no
+ done
+ for port in "${REDIS_PORTS[@]}"; do wait_for 30 "Valkey on :$port" valkey-cli -p "$port" ping; done
+ valkey-cli --cluster create 127.0.0.1:17000 127.0.0.1:17001 127.0.0.1:17002 \
+ --cluster-replicas 0 --cluster-yes >"$LOGS/valkey-cluster-create.log" 2>&1
+ wait_for 30 "the Redis cluster" redis_up
+}
+redis_stop() {
+ local port
+ for port in "${REDIS_PORTS[@]}"; do valkey-cli -p "$port" shutdown nosave >/dev/null 2>&1 || true; done
+}
+
+rabbitmq_up() { rabbitmq-diagnostics -q check_running >/dev/null 2>&1; }
+rabbitmq_start() {
+ if ! rabbitmq_up; then
+ mkdir -p "$RABBITMQ_MNESIA_BASE"
+ setsid rabbitmq-server >>"$LOGS/rabbitmq-server.out" 2>&1 < /dev/null &
+ wait_for 120 RabbitMQ rabbitmq_up
+ fi
+ rabbitmqctl -q add_user "$RABBITMQ_DEFAULT_USER" "$RABBITMQ_DEFAULT_PASS" >/dev/null 2>&1 \
+ || rabbitmqctl -q change_password "$RABBITMQ_DEFAULT_USER" "$RABBITMQ_DEFAULT_PASS" >/dev/null
+ rabbitmqctl -q set_user_tags "$RABBITMQ_DEFAULT_USER" administrator >/dev/null
+ rabbitmqctl -q set_permissions -p / "$RABBITMQ_DEFAULT_USER" '.*' '.*' '.*' >/dev/null
+}
+rabbitmq_stop() {
+ if rabbitmq_up; then rabbitmqctl -q shutdown >/dev/null 2>&1 || true; fi
+}
+
+clamav_up() { echo PING | nc -w 2 127.0.0.1 3310 2>/dev/null | grep -q PONG; }
+clamav_start() {
+ clamav_up && return 0
+ install -d /run/clamav
+ clamd --config-file=/etc/autogpt-scanner/clamd.conf
+ wait_for 60 ClamAV clamav_up
+}
+clamav_stop() {
+ if [ -f /run/clamav/clamd.pid ]; then kill "$(cat /run/clamav/clamd.pid)" 2>/dev/null || true; fi
+ rm -f /run/clamav/clamd.pid
+}
+
+usage() {
+ sed -n '2,10s/^# \{0,1\}//p' "$0" >&2
+ exit 2
+}
+
+command=${1:-}
+[ $# -gt 0 ] && shift
+services=("$@")
+[ ${#services[@]} -gt 0 ] || services=(postgres redis rabbitmq clamav)
+for service in "${services[@]}"; do
+ case "$service" in postgres | redis | rabbitmq | clamav) ;; *) usage ;; esac
+done
+
+case "$command" in
+ start)
+ for service in "${services[@]}"; do "${service}_start"; echo "$service: up"; done
+ ;;
+ stop)
+ for ((i = ${#services[@]} - 1; i >= 0; i--)); do "${services[i]}_stop"; echo "${services[i]}: stopped"; done
+ ;;
+ restart)
+ "$0" stop "${services[@]}"
+ "$0" start "${services[@]}"
+ ;;
+ status)
+ down=0
+ for service in "${services[@]}"; do
+ if "${service}_up"; then echo "$service: up"; else echo "$service: down"; down=1; fi
+ done
+ exit "$down"
+ ;;
+ *) usage ;;
+esac
+EOF
+
+COPY <<'EOF' /etc/rabbitmq/rabbitmq.conf
+listeners.tcp.default = 127.0.0.1:5672
+distribution.listener.interface = 127.0.0.1
+log.file.level = info
+EOF
+
+# ClamAV with the limits CI gives it. The full signature database is hundreds of megabytes to download and over a
+# gigabyte of memory once loaded, and no test needs it: the tests mock detections, and only need clean files to scan
+# clean. The one signature here is the EICAR test file's, as given in ClamAV's documentation, so an upload can still
+# be shown to be caught.
+COPY <<'EOF' /etc/autogpt-scanner/clamd.conf
+TCPSocket 3310
+TCPAddr 127.0.0.1
+DatabaseDirectory /var/lib/autogpt-services/clamav
+LogFile /var/log/autogpt-services/clamd.log
+PidFile /run/clamav/clamd.pid
+StreamMaxLength 50M
+MaxFileSize 100M
+MaxScanSize 100M
+MaxThreads 4
+ReadTimeout 300
+EOF
+RUN install -d /var/lib/autogpt-services/clamav \
+ && echo '44d88612fea8a8f36de82e1278abb02f:68:Eicar-Test-Signature' > /var/lib/autogpt-services/clamav/eicar.hdb
+
+# RabbitMQ listens on IPv4 only, so the backend is pointed at 127.0.0.1: "localhost" makes it try ::1 first and
+# log a connection error for every service it starts.
+COPY <<'EOF' /etc/autogpt-scanner/common.env
+# Connection settings for the services `autogpt-services start` runs, and the secrets the backend needs.
+export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
+export DIRECT_URL=$DATABASE_URL
+export REDIS_HOST=localhost REDIS_PORT=17000
+export RABBITMQ_HOST=127.0.0.1
+export SKILLS_CATALOG_PATH=/opt/skills-catalog
+. /etc/autogpt-scanner/secrets.env
+EOF
+
+# Login shells reset PATH in /etc/profile, then read this.
+COPY <<'EOF' /etc/profile.d/autogpt-scanner.sh
+export PATH="/opt/poetry/bin:/usr/lib/postgresql/15/bin:/opt/rabbitmq/sbin:/opt/erlang/bin:$PATH"
+EOF
+
+COPY <<'EOF' /etc/autogpt-scanner/test.env
+# . /etc/autogpt-scanner/test.env: the environment backend CI runs the tests in
+# (.github/workflows/platform-backend-ci.yml), pointed at the services `autogpt-services start` runs.
+. /etc/autogpt-scanner/common.env
+export CI=true PLAIN_OUTPUT=True RUN_ENV=local PORT=8080 TRIAL_TEST_DATABASE=1
+export EXECUTION_MANAGER_PORT=18002 EXECUTION_SCHEDULER_PORT=18003 DATABASE_API_PORT=18005
+export AGENT_API_PORT=18006 NOTIFICATION_SERVICE_PORT=18007
+EOF
+
+COPY <<'EOF' /etc/autogpt-scanner/stack.env
+# . /etc/autogpt-scanner/stack.env: the environment for running the platform locally (`poetry run rest` and the
+# other entry points in the backend, `pnpm start` in the frontend), on the default ports the frontend build was
+# made for. The backend behaves as the hosted service does (cloud mode, with credits), not as a local install, which
+# grants every paid feature and skips some limits.
+. /etc/autogpt-scanner/common.env
+export PLATFORM_BASE_URL=http://localhost:8006 FRONTEND_BASE_URL=http://localhost:3000
+export JWT_JWKS_URL=http://localhost:3000/api/auth/jwks
+export BEHAVE_AS=cloud ENABLE_CREDIT=true
+EOF
+
+# Secrets for this image only, made when it is built: the backend refuses to start without the first two.
+RUN { \
+ echo "export ENCRYPTION_KEY=$(openssl rand -base64 32 | tr '+/' '-_')"; \
+ echo "export UNSUBSCRIBE_SECRET_KEY=$(openssl rand -base64 32 | tr '+/' '-_')"; \
+ echo "export RABBITMQ_DEFAULT_USER=rabbitmq_user_default"; \
+ echo "export RABBITMQ_DEFAULT_PASS=$(openssl rand -hex 16)"; \
+ } > /etc/autogpt-scanner/secrets.env
+
+# A PostgreSQL cluster holding the database CI tests against, migrated to this checkout's schema; then a check
+# that every service starts.
+WORKDIR /src/autogpt_platform/backend
+RUN install -d -o postgres -g postgres -m 0700 "$PGDATA" \
+ && runuser -u postgres -- /usr/lib/postgresql/15/bin/initdb -D "$PGDATA" \
+ --username=postgres --auth=trust --encoding=UTF8 --locale=C.UTF-8 >/dev/null \
+ && echo "listen_addresses = 'localhost'" >> "$PGDATA/postgresql.conf" \
+ && autogpt-services start postgres \
+ && psql -h localhost -U postgres -d postgres -v ON_ERROR_STOP=1 -q -f /src/autogpt_platform/db/init/00-init.sql \
+ && . /etc/autogpt-scanner/test.env \
+ && poetry run prisma migrate deploy \
+ && autogpt-services start \
+ && autogpt-services status \
+ && autogpt-services stop
+
+WORKDIR /src
diff --git a/.oss-scanner/Dockerfile.dockerignore b/.oss-scanner/Dockerfile.dockerignore
new file mode 100644
index 0000000000..079ec98e77
--- /dev/null
+++ b/.oss-scanner/Dockerfile.dockerignore
@@ -0,0 +1,9 @@
+# Docker reads this file instead of the repository's .dockerignore when it builds .oss-scanner/Dockerfile (an
+# ignore file named after a Dockerfile, next to it, takes precedence). The repository's one is written for the
+# product images: it leaves out everything but a few folders, so autogpt_platform/db/ is missing, and every hidden
+# file, so .nvmrc is too. This build reads both, and the scanner expects the whole checkout in /src, so leave out
+# only what a fresh clone never has.
+**/node_modules/
+**/.venv/
+**/.next/
+**/__pycache__/
diff --git a/.oss-scanner/threat_model.md b/.oss-scanner/threat_model.md
new file mode 100644
index 0000000000..e61d95bbbb
--- /dev/null
+++ b/.oss-scanner/threat_model.md
@@ -0,0 +1,284 @@
+# AutoGPT Platform threat model
+
+## What AutoGPT is and how it is deployed
+
+AutoGPT Platform (`autogpt_platform/` in this repository) is for building, running and sharing AI agents. Users
+build agents as graphs of **blocks** (about 450 of them): LLM calls, web requests, file and media processing, code
+execution, and integrations with dozens of third-party services. They can also ask **AutoPilot** (called "copilot"
+in the code), the platform's own LLM agent, which builds and runs agents for them and has tools of its own: a
+sandboxed shell, a headless browser, web fetch and search, file storage, MCP servers and chat-platform bots.
+
+Both ways it is deployed are in scope:
+
+- **The hosted service at https://platform.agpt.co**, run by the maintainers. It is multi-tenant and anyone can
+ sign up. Users store third-party credentials (API keys and OAuth tokens), pay for usage with credits, publish
+ agents to a public marketplace and work together in organizations (teams). Do not test against it: reproduce
+ locally (see "How to exercise it").
+- **Self-hosted**, with `autogpt_platform/docker-compose.yml` or the single-container image
+ (`autogpt_platform/single-container/`), often for one person or a small team.
+
+The main components:
+
+- `autogpt_platform/backend/backend/`: the backend (Python, FastAPI, Prisma on PostgreSQL, Redis, RabbitMQ).
+ - `api/`: the REST API (`rest_api.py`, routers in `api/features/*`), the WebSocket API (`ws_api.py`,
+ `conn_manager.py`), the external API that API keys and OAuth apps use (`api/external/`), and AutoGPT's own
+ OAuth 2.0 provider, "Sign in with AutoGPT" (`api/features/oauth.py`).
+ - `data/`: the data layer, where most per-user and per-organization scoping happens.
+ - `executor/` and `blocks/`: the engine that runs graphs, and the blocks. `util/request.py` is the HTTP client
+ blocks are meant to use; it carries the SSRF protections.
+ - `integrations/`: credential storage (`credentials_store.py`, `creds_manager.py`), third-party OAuth flows
+ (`oauth/`) and inbound webhooks (`webhooks/`).
+ - `copilot/`: AutoPilot. Its tools are in `copilot/tools/`. Code runs in an E2B sandbox
+ (`tools/e2b_sandbox.py`) or, without E2B, in bubblewrap (`tools/sandbox.py`, `tools/bash_exec.py`). Its
+ permission model is in `permissions.py`, `session_permissions.py` and `tools/capability_gates.py`; sharing is
+ in `sharing/`, chat-platform bots in `bot/` and `../platform_linking/`.
+ - `util/`: shared code, notably `encryption.py`, `cache.py`, `workspace.py`, `workspace_storage.py`,
+ `cloud_storage.py`, `file.py`, `virus_scanner.py` and `secrets_guard.py`.
+- `autogpt_platform/autogpt_libs/`: shared library. `auth/` verifies the JWTs the frontend's auth service issues;
+ `api_key/` makes and checks API keys.
+- `autogpt_platform/frontend/`: Next.js. It hosts the Better Auth service (`src/lib/auth/`, `src/app/api/auth/`),
+ the session middleware (`src/middleware.ts`), a proxy to the backend (`src/app/api/proxy/[...path]/route.ts`)
+ and admin impersonation (`src/lib/impersonation.ts`). It renders user- and model-generated content: markdown,
+ code, and HTML previews in sandboxed iframes (`src/lib/iframe-sandbox-csp.ts`).
+
+## Who the attacker is
+
+In priority order:
+
+1. **An unauthenticated client of the hosted service**: REST, WebSocket, external API, OAuth and auth endpoints,
+ webhook ingress and file downloads.
+2. **Any signed-up user** attacking other users, other organizations or the platform. Every user is untrusted, and
+ the platform runs everyone's agents on shared infrastructure.
+3. **Someone who shares something malicious**: an agent, marketplace listing, shared chat or file that a victim
+ imports, runs or opens.
+4. **Untrusted content an agent or AutoPilot processes**: web pages, emails, documents, API responses, webhook
+ payloads and model output. Prompt injection counts only when it makes the platform cross a boundary (see "Out of
+ scope").
+5. **A third party sending webhooks**: the payload is untrusted until its signature is verified.
+6. **A malicious web page** in a logged-in user's browser: CSRF, XSS, open redirects in the sign-in and OAuth
+ flows.
+
+Trusted: the platform's operators and admin-role users, the server's environment and configuration, and the
+third-party services' own infrastructure.
+
+## What we want reported
+
+- **Authentication**: Better Auth sign-up, sign-in, password reset and email verification; session and JWT
+ issuance and verification (`autogpt_libs/auth/`); API keys; the OAuth provider (PKCE, redirect URIs, scopes, code
+ exchange, refresh tokens); admin impersonation.
+- **Authorization**: user and organization isolation on every route, WebSocket subscription and executor path.
+ That covers graphs, executions and their outputs, schedules, presets, the library, files and workspaces, chats
+ and AutoPilot sessions, credentials, API keys, webhooks and notifications, plus admin-only routes and roles within
+ an organization.
+- **Credentials**: a user's stored third-party credentials must never be readable, usable or exfiltrable by anyone
+ else. That includes through a graph, a shared or marketplace agent, AutoPilot, logs, error messages or exports.
+ The same goes for platform-managed credentials and the server's own secrets.
+- **Code execution**: user input must not run code on the backend or executor hosts. Known routes are blocks,
+ templates, deserialization, file and media processing, and disabled blocks. AutoPilot's shell is meant to run
+ only in E2B or bubblewrap. Escaping that sandbox to the host, to other sandboxes, to other users' files or, when
+ networking is blocked, to the network is in scope.
+- **SSRF**: any outbound request a user can direct must not reach private networks, link-local and cloud metadata
+ addresses, or the platform's own services. That covers blocks, web fetch, MCP servers, webhooks, OAuth and MCP
+ discovery, SMTP, RSS, and image and media URLs. Known bypasses include redirects, DNS rebinding, alternative IP
+ encodings and IPv6 forms.
+- **Money**: credits, budgets and rate limits, billing and Stripe webhooks. This covers anything that lets a user
+ spend paid LLM or third-party usage at the platform's expense or someone else's.
+- **Files and storage**: workspace uploads and downloads, signed URLs, marketplace media, path traversal,
+ content-type and inline rendering, and getting past the virus scan.
+- **Frontend**: stored or DOM XSS, especially from agent output, marketplace content, chats and markdown. Also
+ escapes from the HTML-preview iframe sandbox, open redirects, CSRF, and tokens leaking through the backend proxy.
+- **Denial of service** against shared services from one cheap request or agent run (see "How we rate severity").
+
+## Past vulnerabilities worth looking for variants of
+
+All are fixed and published at https://github.com/Significant-Gravitas/AutoGPT/security/advisories. Variants in
+other blocks, endpoints and code paths are exactly what we want.
+
+- **SSRF that bypasses the request wrapper**: via IPv6 (GHSA-4c8v-hwxc-2356), via IPv4-mapped IPv6 and CGNAT
+ addresses (GHSA-8qc5-rhmg-r6r6) and via DNS rebinding (GHSA-wvjg-9879-3m7w); also cookies and protected headers
+ forwarded across redirects (GHSA-ggcm-93qg-gfhp).
+- **Blocks that make requests without the wrapper**: ReadRSSFeedBlock (GHSA-r55v-q5pc-j57f), SendDiscordFileBlock
+ (GHSA-ggc4-4fmm-9hmc) and SendEmailBlock's SMTP host (GHSA-4jwj-6mg5-wrwf).
+- **Blocks that should not be runnable**: running disabled blocks gave RCE (GHSA-r277-3xc5-c79v,
+ GHSA-4crw-9p35-9x54), and executing a block directly skipped credit charges (GHSA-8pjg-mfqm-vrhr).
+- **Cross-user access**: session hijacking through an IDOR (GHSA-q58p-v9r9-7gqj), node execution results leaking to
+ other users over WebSockets (GHSA-958f-37vw-jx8f), and graph execution through the external API without
+ authorization (GHSA-x77j-qg2x-fgg6).
+- **Webhooks**: provider path confusion that skipped signature verification (GHSA-349p-3c3r-8mjr), binding
+ another user's webhook to a preset (GHSA-4m2w-qfr5-9f3v), and an IDOR in the ping endpoint
+ (GHSA-rq9m-xvc7-v9h6).
+- **Secrets**: a hard-coded default JWT secret and Fernet key (GHSA-24q6-6h89-f9p7, GHSA-57mf-wqwq-6g6x), API keys
+ logged in plain text (GHSA-rc89-6g7g-v5v7), and unsafe `pickle` deserialization of Redis cache entries
+ (GHSA-rfg2-37xq-w4m9).
+- **Frontend**: DOM XSS and an open redirect on the sign-up page (GHSA-j2cp-jg5q-38wj).
+- **Resource exhaustion from one agent run or request**:
+ - media blocks (GHSA-rg6v-m9x9-7wf9, GHSA-g26x-xwc5-7p44, GHSA-267x-8jx3-gg6w)
+ - screenshot and file blocks (GHSA-7g34-7fvq-xxq6, GHSA-9fr4-9jj9-mhh6)
+ - regular expressions, text templating and text chunking (GHSA-m2wr-7m3r-p52c, GHSA-pppq-xx2w-7jpq,
+ GHSA-ppw9-h7rv-gwq9, GHSA-955p-gpfx-r66j)
+ - unauthenticated disk exhaustion (GHSA-374w-2pxq-c9jp)
+
+## Out of scope
+
+- **`classic/`** (the original AutoGPT agent, Forge and the benchmark) is unsupported; see `SECURITY.md`.
+- **Development defaults documented as such**: the RabbitMQ credentials and database passwords in the
+ docker-compose files, in CI and in `.env.default`, and the dev-only VAPID keypair there. A default that the
+ application *accepts in a production configuration* is in scope; the JWT-secret and Fernet-key advisories above
+ are examples.
+- **Prompt injection on its own**, meaning a model that says something, or acts within the permissions its user
+ already gave the session. It is in scope when injected content makes the platform cross a boundary listed above:
+ using credentials or data the session was not granted, reaching another user's data, escaping a sandbox,
+ getting past a permission or approval the user set, or exfiltrating platform secrets.
+- **A user attacking only themselves**: self-XSS, running code in their own sandbox, spending their own credits.
+- **Local-development behavior.** Deployments run `APP_ENV=dev` or `prod` and `BEHAVE_AS=cloud`. Anything that
+ happens only under `APP_ENV=local` or `BEHAVE_AS=local` is out of scope: the `/docs` page, the test-data routes,
+ `FORCE_ALL_FLAGS`, the Teams bot's unverified mode, and the paid features and limits a local install waives.
+ `APP_ENV` is `local` in this image so that flags can be forced on.
+- **Vulnerabilities in third-party dependencies or services**, unless the way AutoGPT uses them creates the
+ problem.
+- **Rate-limit and anti-abuse gaps** with no security or cost impact.
+- **Other paths**: `docs/` (except content the backend serves to AutoPilot), tests, and
+ `autogpt_platform/analytics/`.
+
+## Which code matters most
+
+Backend paths are relative to `autogpt_platform/backend/` (the Python package is `backend`), frontend paths to
+`autogpt_platform/frontend/`.
+
+- **Highest**:
+ - `backend/api/` (including `api/external/` and `api/features/oauth.py`), `autogpt_libs/auth/`,
+ `autogpt_libs/api_key/`
+ - `backend/data/`: the queries that scope by user and organization
+ - `backend/integrations/`: credentials, OAuth and webhooks
+ - `backend/copilot/tools/` and the sandboxes, plus `backend/copilot/permissions.py` and
+ `session_permissions.py`
+ - `backend/util/request.py`, and every block that makes network calls or touches files
+ - `backend/executor/`
+ - frontend `src/lib/auth/`, `src/middleware.ts` and `src/app/api/`
+- **Medium**:
+ - the rest of `backend/blocks/` and `backend/copilot/`
+ - `backend/notifications/`, `backend/platform_linking/`
+ - the marketplace (`api/features/store/`), billing (`api/features/billing/`, `data/credit.py`) and organizations
+ (`api/features/orgs/`)
+ - frontend components that render user or model content
+- **Lower**:
+ - `autogpt_platform/installer/`, `autogpt_platform/single-container/`, `autogpt_platform/swap_proxy/`,
+ `autogpt_platform/cloudflare_worker.js`, `autogpt_platform/graph_templates/`
+
+## How to exercise it
+
+The image has no network access; everything below works offline. The backend is installed in
+`autogpt_platform/backend/.venv` (run it through `poetry run`), the frontend in
+`autogpt_platform/frontend/node_modules`, with a production build in `.next/`.
+
+**Services.** `autogpt-services start` starts:
+
+- PostgreSQL 15 with pgvector on `:5432` (user `postgres`, trust auth); the database is already migrated
+- a 3-shard Redis cluster (Valkey) on `:17000`-`:17002`
+- RabbitMQ on `:5672`
+- ClamAV on `:3310`, which scans every upload. Its only signature is the EICAR test file's, so use that file to
+ show a scan being bypassed.
+
+`autogpt-services status` and `autogpt-services stop` do what they say. Logs are in `/var/log/autogpt-services`.
+
+**Backend tests** use pytest, with `*_test.py` files next to the code they test:
+
+```
+autogpt-services start
+. /etc/autogpt-scanner/test.env # the environment backend CI uses
+cd /src/autogpt_platform/backend
+poetry run pytest -q backend/api/features/library
+```
+
+- Tests that need the Internet fail or skip offline, as expected: LLM providers, third-party APIs, E2B, cloud
+ storage, and the cases in `backend/util/request_test.py` that resolve real hostnames.
+- The whole suite is slow on two CPUs; CI splits it four ways (`.github/scripts/backend_test_shard.py`). Run the
+ directories you need.
+- The route tests (`backend/api/features/**/*_test.py`) show how to call a route as a given user with FastAPI's
+ `TestClient`. That is the quickest way to demonstrate an authorization bug.
+
+**The platform**, to reproduce through real HTTP. Start only the backend services you need. The four below take
+about 5 GB; all of the backend's services at once (`poetry run app`) take more memory than this machine has.
+
+```
+autogpt-services start
+. /etc/autogpt-scanner/stack.env
+cd /src/autogpt_platform/backend
+(poetry run rest > /tmp/rest.log 2>&1 &) # REST API :8006
+(poetry run db > /tmp/db.log 2>&1 &) # database manager :8005, which the other services call
+(poetry run executor > /tmp/executor.log 2>&1 &) # runs agents
+cd /src/autogpt_platform/frontend
+(pnpm start > /tmp/frontend.log 2>&1 &) # Next.js and Better Auth :3000
+```
+
+- The other entry points are `ws` (WebSocket API, `:8001`), `scheduler`, `notification` and `copilot-executor`.
+- `stack.env` runs the backend as the hosted service does: `BEHAVE_AS=cloud`, with credits on.
+- **Accounts** are made through Better Auth: `POST http://localhost:3000/api/auth/sign-up/email` with
+ `{"email": ..., "password": ..., "name": ...}` (passwords are at least 12 characters), an
+ `Origin: http://localhost:3000` header, and a cookie jar. Email verification is off, and sign-up also creates the
+ user's backend record.
+- **Tokens**: `GET http://localhost:3000/api/auth/token` with that cookie returns `{"token": ...}`, a JWT valid
+ for an hour. The backend takes it as `Authorization: Bearer <jwt>`.
+- **Admins**: `psql -h localhost -U postgres -c "UPDATE \"UserAuthIdentity\" SET role = 'admin' WHERE email = '...'"`,
+ then sign in again (`POST http://localhost:3000/api/auth/sign-in/email` with the email and password) and fetch a
+ token from the new session; the old session keeps the old role. An admin can give a user credits with
+ `POST /api/credits/admin/add_credits`.
+- **Feature flags** come from LaunchDarkly, which isn't configured here, so every flag is off.
+ `FORCE_FLAG_<KEY>=true` in the backend's environment turns one on (the flag key upper-cased, with `-` as `_`), and
+ `FORCE_ALL_FLAGS=true` turns them all on. Code behind a flag is in scope: the hosted service turns flags on for
+ some or all users.
+- `next start` warns that it doesn't work with standalone output; it serves everything anyway.
+- Anything that needs an API key logs errors and fails offline (LLM calls, embeddings, third-party integrations).
+
+**Frontend tests** use Vitest with MSW, which works offline. Most test files are in `__tests__` folders next to the
+code they test:
+
+```
+cd /src/autogpt_platform/frontend
+pnpm exec vitest run src/lib/auth
+```
+
+- The whole suite takes over 30 minutes on two CPUs, so run the folders you need; `src/lib/auth` takes 40 seconds.
+- Playwright browsers are not installed.
+
+## How we rate severity
+
+- **Critical**:
+ - remote code execution on the backend or executor hosts, by anyone with an account or none
+ - authentication bypass or takeover of arbitrary accounts
+ - reading or using another user's stored credentials, or the platform's secrets and cloud credentials (for
+ example through SSRF to a metadata endpoint)
+ - access to any user's or organization's private data at will
+- **High**:
+ - escaping AutoPilot's sandbox to the host
+ - SSRF that returns responses from internal addresses
+ - IDOR that reads or changes another user's or organization's private data, case by case
+ - privilege escalation to admin, or to a higher role within an organization
+ - stored XSS that runs in another user's session
+ - a webhook that triggers runs in someone else's account without a valid signature
+ - running disabled or admin-only blocks
+ - spending the platform's money (LLM or third-party usage) past credit or budget limits
+ - one cheap request or agent run that takes a shared service (API, executor, database) down for everyone
+- **Medium**:
+ - blind SSRF
+ - CSRF that changes state
+ - reflected or DOM XSS that needs a click
+ - open redirects in the sign-in and OAuth flows (high if they leak a token or code)
+ - disclosure of other users' non-secret metadata, such as email addresses
+- **Low**:
+ - denial of service that needs sustained traffic, or that only hurts the attacker's own runs
+ - missing hardening headers and verbose errors
+ - problems that need unusual, non-default configuration
+
+## How reports should look
+
+- Name the attacker from "Who the attacker is" that the exploit assumes: no account, any account, a member of the
+ same organization, a webhook sender, or a victim who must click, open or run something.
+- Reproduce against an unmodified checkout, set up as `stack.env` or `test.env` does, and say which other settings
+ the exploit needs, if any.
+- One report per root cause. If the same missing check affects several routes or blocks, list them all in one
+ report.
+- The reproducer should be a pytest test (a `*_test.py` file next to the code), or a short script or `curl`
+ sequence against the local platform started as above, with the expected and actual result.
+- Patches should be minimal and against the `dev` branch, with a regression test. Backend code is formatted with
+ `poetry run format`, frontend code with `pnpm format`.