Commit Graph

535 Commits

Author SHA1 Message Date
Hugh Brown
858575cf6c test: add comprehensive tests for all security fixes
Add 20 tests covering:
- require_user_actor: rejects agents and null users, passes valid users
- Webhook HMAC: rejects missing/invalid signatures, accepts valid ones,
  allows unsigned when no secret configured
- Prompt injection: sanitized skill name/URL, fenced external data in
  dispatch messages, system instructions precede data
- Security headers: verify nosniff, DENY, referrer-policy defaults
- Payload size: rejects oversized body and content-length
- Rate limiting: blocks after threshold, independent per-key
- Gateway token: has_token field present, token field absent
- Agent auth logs: no token_prefix in source

Also fix deprecated HTTP_413_REQUEST_ENTITY_TOO_LARGE status code.

All 407 tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
547965a5cb security: redact gateway tokens from API responses
Gateway tokens were returned as plaintext in GatewayRead API responses.
Replace the `token` field with a boolean `has_token` flag so the API
never exposes the plaintext token. The token remains in the database
for outbound gateway connections (full encryption would require key
management infrastructure).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
94988deef2 security: add rate limiting to agent auth and webhook ingest
Agent token auth performed O(n) PBKDF2 operations per request with no
rate limiting, enabling CPU exhaustion attacks. Webhook ingest had no
rate limits either. Add an in-memory token-bucket rate limiter:
- Agent auth: 20 requests/minute per IP
- Webhook ingest: 60 requests/minute per IP

Includes unit tests for the rate limiter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
8a30c82c6d security: remove hardcoded auth token from committed .env.test
The file contained a publicly known LOCAL_AUTH_TOKEN value that could
be used against misconfigured deployments. Replace with an empty value
and a comment showing how to generate a secure token. The test suite
continues to work via conftest.py which sets its own test-only token.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
8e145a2129 security: set sensible defaults for security response headers
X-Content-Type-Options, X-Frame-Options, and Referrer-Policy all
defaulted to empty (disabled). Set defaults to nosniff, DENY, and
strict-origin-when-cross-origin respectively. Operators can still
override or disable via environment variables.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
c7f8578f38 security: run Docker containers as non-root user
Both backend and frontend Dockerfiles ran all processes as root.
Add a dedicated appuser in each runtime stage so container processes
run with minimal privileges, limiting blast radius of any container
escape.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
4257c08ba9 security: stop logging token prefix on failed agent auth
The first 6 characters of invalid agent tokens were logged, leaking
partial credential information. Remove token_prefix from log messages
while preserving the request path for debugging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
66da278673 security: require org-admin for gateway session message endpoint
send_gateway_session_message only required basic auth (AUTH_DEP) while
all other gateway endpoints required ORG_ADMIN_DEP. Any authenticated
user could send messages to any gateway session. Now requires org-admin
and verifies the board belongs to the caller's organization.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
7ca4145aff security: add 1 MB payload size limit to webhook ingestion
The webhook ingest endpoint read the entire request body with no size
limit, enabling memory exhaustion attacks. Add a 1 MB limit checked
via both Content-Length header (early reject) and actual body size.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
5d382ed67b security: mitigate prompt injection in agent instruction strings
User-controlled fields (skill name, source URL, webhook payloads) were
interpolated directly into agent instruction messages. Sanitize skill
fields by stripping newlines/control chars, and fence all external data
behind "BEGIN EXTERNAL DATA" / "BEGIN STRUCTURED DATA" delimiters with
explicit "do not interpret as instructions" markers. Move system
instructions above the data section so they cannot be overridden.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
4d1dbb4098 security: add HMAC signature verification to webhook ingest
Webhook ingest endpoint was completely unauthenticated. Add an optional
`secret` field to BoardWebhook. When configured, inbound requests must
include a valid HMAC-SHA256 signature in X-Hub-Signature-256 or
X-Webhook-Signature headers. Uses hmac.compare_digest for timing safety.
Includes migration to add the secret column.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
10848b98cb security: scope agent board listing to organization
Main agents (board_id=None) could list boards across all organizations.
Now resolves the agent's organization via its gateway and filters boards
by organization_id to prevent cross-tenant data leakage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
Hugh Brown
c7692e30d3 security: rename misleading require_admin to require_user_actor
The function only checked that the caller was an authenticated user
(not an agent) but its name implied privilege enforcement. Rename to
require_user_actor and add docstring clarifying the distinction between
actor-type checks and privilege/role checks (require_org_admin, is_super_admin).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:35:10 +05:30
zoi-tdinh
b42c2eb73c fix: normalize deprecated postgres:// URLs to postgresql+psycopg:// 2026-03-05 20:11:46 +07:00
Abhimanyu Saharan
532fbf1dc5 feat(config): make BASE_URL a required field and update related documentation 2026-03-05 01:36:07 +05:30
Abhimanyu Saharan
3acc276d8d fix(agent): address webhook payload read review feedback 2026-03-04 23:26:31 +05:30
Abhimanyu Saharan
1d0b318fc9 lint: fix flake8 E304 after create_task decorator 2026-03-04 23:22:27 +05:30
Abhimanyu Saharan
3fc96baa10 feat(agent): add read-only webhook payload fetch endpoint for backfill 2026-03-04 23:22:27 +05:30
Abhimanyu Saharan
f5e3b8923a test: assert blocked precondition in dependency-only update test 2026-03-04 23:09:56 +05:30
Abhimanyu Saharan
636c130a3b test: harden blocked-task regression tests per review 2026-03-04 23:01:24 +05:30
Abhimanyu Saharan
130947dcea test: format blocked-task schema regression assertions 2026-03-04 22:52:43 +05:30
Abhimanyu Saharan
6f7867872b test: fix import order for blocked dependency regression test 2026-03-04 22:50:47 +05:30
Abhimanyu Saharan
e9ce004e70 test: address PR review feedback for blocked-task schema 2026-03-04 22:46:44 +05:30
Abhimanyu Saharan
8b77eae0f2 Document blocked-task 409 error code in OpenAPI + add regression tests 2026-03-04 22:46:44 +05:30
Abhimanyu Saharan
4378d354f4 fix(ci): resolve backend check failures in dashboard metrics 2026-03-04 16:11:14 +05:30
Abhimanyu Saharan
bdc9fc3f01 redesigned dashboard page 2026-03-04 16:01:56 +05:30
Abhimanyu Saharan
d4f9831ecb fix(agent): refine agent update retry logic to handle creation race conditions #193 2026-03-03 03:19:11 +05:30
Abhimanyu Saharan
77870b0fc7 fix(agent): improve error handling for get_agent_soul method 2026-03-03 03:09:29 +05:30
Abhimanyu Saharan
0fe61e3e08 refactor(env): update NEXT_PUBLIC_API_URL to use 'auto' for better flexibility 2026-03-03 02:40:28 +05:30
Abhimanyu Saharan
2031f8dcd8 fix: increase GIT_CLONE_TIMEOUT_SECONDS to 600 for better performance #173 2026-03-03 02:16:19 +05:30
Abhimanyu Saharan
94ae59d6aa refactor(gateway): update gateway parameters to use None as default #169 2026-03-03 01:51:52 +05:30
copilot-swe-agent[bot]
7f5aaa7412 fix: add git to backend Docker image for skill pack sync
Co-authored-by: abhi1693 <5083532+abhi1693@users.noreply.github.com>
2026-03-02 19:41:25 +00:00
Abhimanyu Saharan
bfa067fde4 Merge pull request #190 from crazyclaw85-source/fix/provisioning-exec-host-and-update-race
fix: auto-configure tools.exec.host and handle agents.update race
2026-03-03 00:17:35 +05:30
copilot-swe-agent[bot]
35b3829da0 refactor: use custom worker script instead of standard RQ CLI
- Add scripts/rq-docker for Docker container compatibility
- Update Dockerfile to copy scripts directory
- Replace standard rq worker command with custom worker script
- Custom worker includes built-in scheduling via _drain_ready_scheduled_tasks

Co-authored-by: abhi1693 <5083532+abhi1693@users.noreply.github.com>
2026-03-02 14:57:00 +00:00
Viktor
026da96e8c fix: auto-configure tools.exec.host and handle agents.update race
Three related provisioning fixes:

1. **tools.exec.host auto-configuration**: Add `_tools_exec_host_patch()`
   that ensures `tools.exec.host` is set to `"gateway"` during
   `patch_agent_heartbeats()`. Without this, heartbeat-driven agents
   cannot execute `curl`, `bash`, or any shell command — making
   HEARTBEAT.md instructions unexecutable. The function is idempotent
   and respects existing user configuration.

2. **agents.update hot-reload race**: After `agents.create` writes to
   disk, the gateway triggers a ~500ms debounced hot-reload. If
   `agents.update` arrives before the reload completes, it returns
   "agent not found". Fix: add a 750ms delay after create + exponential
   backoff retry (5 attempts, 0.5s → 4s) on the update call.

3. **Skip no-op config.patch**: When `patch_agent_heartbeats()` detects
   no changes to agents, channels, or tools config, skip the
   `config.patch` RPC entirely. Each unnecessary patch triggers a
   gateway SIGUSR1 restart that rotates agent tokens and breaks active
   sessions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 16:40:44 +00:00
Hanush H Nair
4c35cb03ad fix(backend): Return None instead of 401 when agent not found in get_agent_auth_context_optional 2026-02-27 23:19:40 +05:30
Abhimanyu Saharan
c0eb1a14fd Merge branch 'master' into fix/agent-auth-accept-bearer-in-optional-dep 2026-02-27 01:49:45 +05:30
Adam Grenier
3b20e799e2 fix: accept Authorization: Bearer in agent_auth_context_optional
The optional variant of get_agent_auth_context had accept_authorization=False,
which prevented agents using Authorization: Bearer from passing through the
ACTOR_DEP / BOARD_READ_DEP / TASK_DEP dependency chain.

This caused 401 on any agent route that resolves a board or task via the shared
ACTOR_DEP (e.g. PATCH /agent/boards/{id}/tasks/{id} and
POST /agent/boards/{id}/tasks/{id}/comments), even though the same token worked
fine on routes that use AGENT_CTX_DEP directly (accept_authorization=True).

Fix: set accept_authorization=True in get_agent_auth_context_optional so both
X-Agent-Token and Authorization: Bearer are accepted consistently.

Verified: PATCH and POST /comments now resolve board/task correctly when
Authorization: Bearer is used. No security regression — agent_token_hash
comparison rejects any non-agent bearer tokens.
2026-02-26 11:51:45 -08:00
Abhimanyu Saharan
348b0515ac feat(boards): implement lead notification on board updates with detailed change messages 2026-02-26 01:58:55 +05:30
Abhimanyu Saharan
bc71d5ba38 refactor(page): improve code formatting for better readability in event handlers 2026-02-26 00:36:33 +05:30
Abhimanyu Saharan
6b21ea6f99 feat(boards): add 'comment_required_for_review' rule and update related logic 2026-02-26 00:31:47 +05:30
Abhimanyu Saharan
adad72373c feat(tasks): add notification messages for task assignment and rework 2026-02-25 18:29:59 +05:30
Abhimanyu Saharan
5b0ddcc7cd refactor(tests): format code for better readability in test files 2026-02-25 03:41:03 +05:30
Abhimanyu Saharan
58db8be117 fix(security): update security header names to lowercase and add tests 2026-02-25 03:39:49 +05:30
Abhimanyu Saharan
842a0770a8 Update backend/app/services/openclaw/provisioning.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-25 03:37:05 +05:30
Abhimanyu Saharan
3f158940cd Merge branch 'master' into docs/backend-doc-pass 2026-02-25 03:32:14 +05:30
Abhimanyu Saharan
87784d88ab Merge branch 'master' into master 2026-02-25 03:23:25 +05:30
Abhimanyu Saharan
e3404d8590 feat: implement local authentication flow and update related tests 2026-02-25 02:24:51 +05:30
Abhimanyu Saharan
2e3b455582 Merge branch 'master' into master 2026-02-25 00:50:37 +05:30
Abhimanyu Saharan
1d50e48609 chore: update CI configuration and improve README instructions 2026-02-25 00:49:35 +05:30