Security: API & Tenancy Audit Report#11
Open
cto-new[bot] wants to merge 1 commit into
Open
Conversation
Reviewer's GuideAdds an initial SECURITY_AUDIT.md document describing current security posture and identified issues in auth middleware, admin key usage, audit trail integration, and future multi-tenant analytics/requests endpoints, without changing application code. Sequence diagram for API key validation and tenancy assignmentsequenceDiagram
actor Client
participant Gateway
participant AuthMiddleware
participant Supabase
Client->>Gateway: HTTP request with Authorization header
Gateway->>AuthMiddleware: Invoke with request
alt Static admin key path
AuthMiddleware->>AuthMiddleware: validate_static_key(api_key)
AuthMiddleware-->>Gateway: set request.state.user_id = admin
Gateway-->>Client: Forward response from downstream handler
else Supabase-backed key path
AuthMiddleware->>AuthMiddleware: _verify_token_supabase(api_key)
note left of AuthMiddleware: This call result is cached via LRU
AuthMiddleware-->>Supabase: Validate api_key and fetch tenant data
Supabase-->>AuthMiddleware: api_key status, user_id, plan_tier
AuthMiddleware-->>Gateway: set request.state.user_id
Gateway-->>Client: Forward response from downstream handler
end
Sequence diagram for intended signed audit trail integrationsequenceDiagram
actor Client
participant Gateway
participant AuthMiddleware
participant AuditMiddleware
participant AuditLogger
participant RedisAuditStream
Client->>Gateway: HTTP request
Gateway->>AuthMiddleware: Authenticate request
AuthMiddleware-->>Gateway: Attach user_id to request.state
Gateway->>AuditMiddleware: Process authenticated request
AuditMiddleware->>AuditLogger: append_event(user_id, path, method, status)
AuditLogger->>AuditLogger: sign_event_with_hmac(secret_key)
AuditLogger->>RedisAuditStream: store_signed_event(tenant_namespace)
RedisAuditStream-->>AuditLogger: ack
AuditMiddleware-->>Gateway: Continue pipeline
Gateway-->>Client: HTTP response
Updated class diagram for auth and audit middleware componentsclassDiagram
class AuthMiddleware {
+call(request, call_next)
-_verify_token_supabase(api_key)
-validate_static_key(api_key)
-FREERELAY_API_KEY
}
class AuditMiddleware {
+call(request, call_next)
-logger
-audit_logger
}
class AuditLogger {
+append_event(user_id, path, method, status)
-sign_event_with_hmac(secret_key, payload)
-store_signed_event(namespace, signed_payload)
-secret_key
}
class RequestState {
+user_id
+plan_tier
}
class RedisAuditStream {
+store_signed_event(namespace, signed_payload)
}
class SupabaseClient {
+validate_api_key(api_key)
+fetch_tenant_data(api_key)
}
AuthMiddleware --> SupabaseClient : uses
AuthMiddleware --> RequestState : sets
AuditMiddleware --> AuditLogger : uses
AuditLogger --> RedisAuditStream : writes_to
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the initial security audit report for FreeRelay.
Key findings include:
Note: I was unable to audit the /v1/analytics and /v1/requests endpoints as the code is not yet present in the repository, despite being marked as done in the task board.
Summary by Sourcery
Documentation: