|
| 1 | +# Wrappers Platform Security |
| 2 | + |
| 3 | +> **Security Disclosure**: If you discover a security vulnerability, please report it via https://supabase.com/.well-known/security.txt |
| 4 | +
|
| 5 | +This document covers security measures implemented across the entire Wrappers platform. For FDW-specific security concerns, see the individual FDW documentation. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 1. Supply Chain Security - WASM Package Verification |
| 10 | + |
| 11 | +### Protection |
| 12 | +WASM FDW servers with remote package URLs **require** the `fdw_package_checksum` option to prevent supply chain attacks. Local `file://` URLs are exempt since they reference locally-built packages. |
| 13 | + |
| 14 | +```sql |
| 15 | +-- This will FAIL - checksum is required |
| 16 | +CREATE SERVER my_server |
| 17 | + FOREIGN DATA WRAPPER wasm_wrapper |
| 18 | + OPTIONS ( |
| 19 | + fdw_package_url 'https://example.com/my_fdw.wasm', |
| 20 | + fdw_package_name 'my-fdw', |
| 21 | + fdw_package_version '1.0.0' |
| 22 | + -- Missing fdw_package_checksum! |
| 23 | + ); |
| 24 | + |
| 25 | +-- This will work |
| 26 | +CREATE SERVER my_server |
| 27 | + FOREIGN DATA WRAPPER wasm_wrapper |
| 28 | + OPTIONS ( |
| 29 | + fdw_package_url 'https://example.com/my_fdw.wasm', |
| 30 | + fdw_package_name 'my-fdw', |
| 31 | + fdw_package_version '1.0.0', |
| 32 | + fdw_package_checksum 'sha256:abc123...' -- Required! |
| 33 | + ); |
| 34 | +``` |
| 35 | + |
| 36 | +### Implementation |
| 37 | +- Enforced in `wrappers/src/fdw/wasm_fdw/wasm_fdw.rs` validator function |
| 38 | +- Checksum is verified when the WASM package is loaded |
| 39 | +- Mismatch causes the query to fail |
| 40 | + |
| 41 | +### Calculating Checksums |
| 42 | +```bash |
| 43 | +sha256sum my_fdw.wasm | awk '{print "sha256:" $1}' |
| 44 | +``` |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +## 2. Credential Masking in Error Messages |
| 49 | + |
| 50 | +### Protection |
| 51 | +All FDW error messages are sanitized to prevent credential leakage using the `sanitize_error_message()` utility. |
| 52 | + |
| 53 | +### Sensitive Patterns Detected |
| 54 | +The following option names are automatically masked: |
| 55 | +- Generic: `password`, `secret`, `token`, `api_key`, `credentials` |
| 56 | +- AWS: `aws_secret_access_key`, `aws_session_token` |
| 57 | +- GCP: `service_account_key` |
| 58 | +- Azure: `client_secret`, `storage_key`, `connection_string` |
| 59 | +- Database: `conn_string`, `db_password` |
| 60 | +- Service-specific: `stripe_api_key`, `firebase_credentials`, `motherduck_token` |
| 61 | + |
| 62 | +### Example |
| 63 | +``` |
| 64 | +Before: "Error: aws_secret_access_key = 'wJalrXUtnFEMI/K7MDENG' is invalid" |
| 65 | +After: "Error: aws_secret_access_key = 'wJal***' is invalid" |
| 66 | +``` |
| 67 | + |
| 68 | +### Implementation |
| 69 | +- Core utility in `supabase-wrappers/src/utils.rs` |
| 70 | +- Applied to error handlers in all FDWs: |
| 71 | + - DuckDB FDW (SQL with embedded credentials) |
| 72 | + - Airtable, Auth0, Firebase, Stripe, Logflare, Cognito FDWs |
| 73 | + |
| 74 | +### Usage in Custom FDWs |
| 75 | +```rust |
| 76 | +use supabase_wrappers::prelude::sanitize_error_message; |
| 77 | + |
| 78 | +impl From<MyFdwError> for ErrorReport { |
| 79 | + fn from(value: MyFdwError) -> Self { |
| 80 | + let error_message = sanitize_error_message(&format!("{value}")); |
| 81 | + ErrorReport::new(PgSqlErrorCode::ERRCODE_FDW_ERROR, error_message, "") |
| 82 | + } |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## 3. Response Size Limits |
| 89 | + |
| 90 | +### Protection |
| 91 | +HTTP-based FDWs enforce configurable response size limits to prevent denial-of-service attacks via maliciously large responses. Responses exceeding the limit are rejected before JSON parsing. |
| 92 | + |
| 93 | +### Configuration |
| 94 | +Set `max_response_size` (in bytes) as a server option: |
| 95 | + |
| 96 | +```sql |
| 97 | +CREATE SERVER stripe_server |
| 98 | + FOREIGN DATA WRAPPER stripe_wrapper |
| 99 | + OPTIONS ( |
| 100 | + api_key_id 'your-vault-secret-id', |
| 101 | + max_response_size '5242880' -- 5 MB limit |
| 102 | + ); |
| 103 | +``` |
| 104 | + |
| 105 | +### Default Value |
| 106 | +All supported FDWs default to **10 MB** (10,485,760 bytes) if not specified. |
| 107 | + |
| 108 | +### Supported FDWs |
| 109 | + |
| 110 | +| FDW | Support | Notes | |
| 111 | +|-----|---------|-------| |
| 112 | +| Stripe | ✅ | Full implementation | |
| 113 | +| Airtable | ✅ | Full implementation | |
| 114 | +| Firebase | ✅ | Full implementation | |
| 115 | +| Logflare | ✅ | Full implementation | |
| 116 | +| Auth0 | ❌ | Uses SDK architecture | |
| 117 | +| Cognito | ❌ | Uses AWS SDK | |
| 118 | +| DuckDB | ❌ | Not HTTP-based | |
| 119 | +| WASM FDWs | Per-FDW | Implemented individually | |
| 120 | + |
| 121 | +### Error Behavior |
| 122 | +When a response exceeds the limit: |
| 123 | +``` |
| 124 | +ERROR: response too large (15728640 bytes). Maximum allowed: 10485760 bytes |
| 125 | +``` |
| 126 | + |
| 127 | +### Implementation |
| 128 | +- Each FDW has a `ResponseTooLarge` error variant |
| 129 | +- Response body is read as text and size-checked before JSON parsing |
| 130 | +- Example in `wrappers/src/fdw/stripe_fdw/stripe_fdw.rs` |
| 131 | + |
| 132 | +### Known Limitations |
| 133 | +The size check occurs **after** the response body is read into memory. This means: |
| 134 | +- An extremely large response could temporarily consume memory before being rejected |
| 135 | +- This protects against storing/parsing oversized data, but not against memory exhaustion during the HTTP read phase |
| 136 | +- For stronger protection, consider network-level controls (e.g., reverse proxy response size limits) |
| 137 | + |
| 138 | +Future improvement: Implement streaming reads with size checking during the read phase. |
| 139 | + |
| 140 | +--- |
| 141 | + |
| 142 | +## 4. Option Value Security |
| 143 | + |
| 144 | +### Protection |
| 145 | +Option values that fail UTF-8 validation do not include the raw bytes in error messages, preventing binary credential leakage. |
| 146 | + |
| 147 | +### Implementation |
| 148 | +- `supabase-wrappers/src/options.rs` - `OptionsError::OptionValueIsInvalidUtf8` only includes option name, not value |
| 149 | + |
| 150 | +--- |
| 151 | + |
| 152 | +## Security Status |
| 153 | + |
| 154 | +| Protection | Status | Location | |
| 155 | +|------------|--------|----------| |
| 156 | +| WASM checksum required | ✓ Implemented | `wasm_fdw.rs` validator | |
| 157 | +| Credential masking | ✓ Implemented | `utils.rs`, all FDW error handlers | |
| 158 | +| Response size limits | ✓ Implemented | Stripe, Airtable, Firebase, Logflare FDWs | |
| 159 | +| Option value protection | ✓ Implemented | `options.rs` | |
| 160 | + |
| 161 | +--- |
| 162 | + |
| 163 | +## FDW-Specific Security |
| 164 | + |
| 165 | +Each FDW may have additional security considerations: |
| 166 | + |
| 167 | +- **AWS FDW**: SSRF protection for `endpoint_url` - see `wasm-wrappers/fdw/aws_fdw/SECURITY.md` |
| 168 | +- **DuckDB FDW**: SQL injection via server type options |
| 169 | +- **HTTP-based FDWs**: Request/response validation |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +## Reporting Security Issues |
| 174 | + |
| 175 | +Please report security vulnerabilities to the Supabase security team rather than opening public issues. |
0 commit comments