mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-05 12:28:15 +01:00
* fix(security): SSRF guard for webhook URLs; scrub committed Supabase PATs - Webhook URLs are fetched server-side and the response body is readable by the endpoint owner, so internal targets (localhost, RFC1918, link-local/cloud metadata, CGNAT, reserved) are now rejected at mint time and re-checked before every delivery (src/lib/security/ssrfGuard.ts, 30 unit tests). Dev keeps localhost receivers working. - Delete scripts/db/apply-migration.sh (orphaned one-off carrying a hardcoded sbp_ token for the retired managed-cloud project) and redact the second dead token in docs/archive. Both tokens are dead — the managed Supabase Cloud project was retired 2026-06. - Add .gitleaks.toml: the default ruleset has no Supabase PAT pattern (why these sat unflagged); new sbp_ rule with the two dead historical tokens allowlisted so the full-history CI scan stays green. - Update SECURITY.md and API conventions doc (webhooks section was still marked "planned — not yet built"; now documents the shipped behavior including the URL policy). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TxtUEaJPtYviTwrr5Sf7Pn * perf(timeline): batch feed enrichment; parallelize reply tree and nudges - getEnrichedUserFeed did up to 3 single-row lookups PER EVENT (~60 round-trips for a 20-item dashboard/timeline page) while the batched enrichEventsForDisplay (3 queries total, already used elsewhere) sat unused — switch to it and zip the social counters back in by index. - getReplies awaited each reply subtree sequentially — now Promise.all, so thread latency no longer grows linearly with reply count. - generateNudges queried each entity type serially on the force-dynamic /api/cat/nudges path — now parallel. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TxtUEaJPtYviTwrr5Sf7Pn * fix(entities): registry is the one source for ownership columns; guard it in CI - entityListHandler now derives the ownership column from the entity registry's userIdField instead of defaulting to 'user_id'; drop the redundant userIdField:'actor_id' literals from the 8 list routes. - The profile-entities route kept its own copy of the ownership map, which had drifted (research: 'user_id') — consolidated onto getUserIdField(). - createResearch inserted without actor_id even though research_entities.actor_id is NOT NULL on the live schema — research creation could not succeed. Dual-write user_id + actor_id, same pattern as ai_assistants. - New CI guard: entity-registry-live-schema.test.ts asserts every registry tableName / userIdField / priceColumn exists in scripts/db/live-schema.json (the live-DB snapshot the deploy pipeline refreshes). - Mark src/types/database.ts as known-stale in its header: it disagrees with the live schema (missing actor_id on several tables, missing events/user_documents entirely) and gen:types writes a different file that nothing imports — do not treat it as schema ground truth. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TxtUEaJPtYviTwrr5Sf7Pn * test(ci): gate every Jest suite; repair Jest-30-broken scripts; coverage floor - test:unit only matched __tests__/unit, silently excluding 22 suites / ~280 tests under tests/unit (webhook signature crypto, idempotency keys, hasScope authorization) plus smoke/create/env — nothing gated them. The pattern now matches everything Jest discovers (94 suites, 1095 tests, ~5s), so CI and the git hooks run the full fast suite. - test:security / test:integration / test:performance / test:auth used the singular --testPathPattern flag that Jest 30 hard-rejects (and test:auth pointed at a directory that doesn't exist) — all four were broken; security:scan errored because of it. Repaired with plural flags, real patterns, and --passWithNoTests where the target set is currently empty. - Add a coverage ratchet floor in jest.config.js just below measured coverage so it can only move up. - Update developer docs that still showed the removed singular flag. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TxtUEaJPtYviTwrr5Sf7Pn --------- Co-authored-by: Claude <noreply@anthropic.com>
created_date, last_modified_date, last_modified_summary
| created_date | last_modified_date | last_modified_summary |
|---|---|---|
| 2025-06-05 | 2025-06-05 | Added documentation standards including creation and modification dates |
�� API Documentation
REST API Reference for OrangeCat
📋 Overview
OrangeCat provides a comprehensive REST API for managing Bitcoin fundraising projects, user profiles, and authentication. All API endpoints follow RESTful conventions and return JSON responses.
Base URL: /api/
Authentication: JWT tokens via Supabase Auth
Rate Limiting: Applied per endpoint
🔐 Authentication
All protected endpoints require authentication via JWT tokens:
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
📚 API Sections
🔐 Authentication Endpoints
- Authentication API - Login, register, password reset
👤 Profile Management
- Profile API - User profile CRUD operations
💰 Campaign Management
- Campaign API - Fundraising project operations
📁 File Upload
- Upload API - Avatar and banner image uploads
🤖 AI Chat
- Chat API - AI assistant integration using Google Gemini
🎯 Quick Start
1. Authentication
// Login
POST /api/auth/login
{
"email": "user@example.com",
"password": "password"
}
2. Get Profile
// Get current user profile
GET /api/profile
Authorization: Bearer {token}
3. Create Campaign
// Create new project
POST /api/projects
Authorization: Bearer {token}
{
"title": "My Campaign",
"description": "Campaign description",
"goal_amount": 1000000
}
📊 Response Format
Success Response
{
"success": true,
"data": { ... },
"message": "Operation successful"
}
Error Response
{
"success": false,
"error": "Error message",
"code": "ERROR_CODE"
}
🔒 Security
- Input Validation - All inputs validated and sanitized
- Rate Limiting - Protection against abuse
- CORS - Configured for secure cross-origin requests
- HTTPS Only - All API calls must use HTTPS in production
📈 Rate Limits
| Endpoint Type | Limit | Window |
|---|---|---|
| Authentication | 5 requests | 1 minute |
| Profile Updates | 10 requests | 1 minute |
| File Uploads | 3 requests | 1 minute |
| General API | 100 requests | 1 minute |
🐛 Error Codes
| Code | Description |
|---|---|
AUTH_REQUIRED |
Authentication required |
INVALID_TOKEN |
Invalid or expired token |
VALIDATION_ERROR |
Input validation failed |
RATE_LIMIT_EXCEEDED |
Too many requests |
RESOURCE_NOT_FOUND |
Resource not found |
PERMISSION_DENIED |
Insufficient permissions |
📚 Related Documentation
- Authentication System - Complete auth flow
- Security Guidelines - Security best practices
- Development Setup - Local API development