Translated ['', 'src/pentesting-ci-cd/supabase-security.md'] to ja

This commit is contained in:
Translator
2025-09-29 23:06:30 +00:00
parent 68829962b3
commit 12c692fc8a

View File

@@ -1,49 +1,49 @@
# Supabase Security
# Supabase セキュリティ
{{#include ../banners/hacktricks-training.md}}
## 基本情報
彼らの[**ランディングページ**](https://supabase.com/)によるとSupabaseはオープンソースのFirebase代替です。Postgresデータベース、認証、インスタントAPI、エッジ関数、リアルタイムサブスクリプション、ストレージ、ベクトル埋め込みを使用してプロジェクトを開始します。
公式の[**landing page**](https://supabase.com/)によるとSupabase はオープンソースの Firebase 代替です。プロジェクトは Postgres データベース、Authentication、instant APIs、Edge Functions、Realtime subscriptions、Storage、Vector embeddings で開始できます。
### サブドメイン
基本的にプロジェクトが作成されると、ユーザーはsupabase.coサブドメインを受け取ります:**`jnanozjdybtpqgcwhdiz.supabase.co`**
基本的にプロジェクトが作成されると、ユーザーは次のような supabase.co サブドメインを受け取ります:**`jnanozjdybtpqgcwhdiz.supabase.co`**
## **データベース設定**
## **Database configuration**
> [!TIP]
> **このデータには、`https://supabase.com/dashboard/project/<project-id>/settings/database`のようなリンクからアクセスできます**
> **This data can be accessed from a link like `https://supabase.com/dashboard/project/<project-id>/settings/database`**
この**データベース**は、いくつかのAWSリージョンにデプロイされ、接続するには次のように接続することができます:`postgres://postgres.jnanozjdybtpqgcwhdiz:[YOUR-PASSWORD]@aws-0-us-west-1.pooler.supabase.com:5432/postgres`これはus-west-1作成されました)。\
パスワードは**ユーザーが前に設定したパスワード**です。
この **database** はいずれかの AWS リージョンにデプロイされ、接続するには次のように接続できます:`postgres://postgres.jnanozjdybtpqgcwhdiz:[YOUR-PASSWORD]@aws-0-us-west-1.pooler.supabase.com:5432/postgres`(これは us-west-1作成されました)。\
パスワードはユーザーが前に設定した **password** です。
したがって、サブドメイン既知のものであり、ユーザー名として使用され、AWSリージョン限られているため、**パスワードをブルートフォースする**ことが可能かもしれません。
したがって、サブドメイン既知ユーザー名として使れ、AWSリージョン限られているため、**brute force the password** を試みることが可能かもしれません。
このセクションには、次のオプションも含まれています:
このセクションでは次のオプションもあります:
- データベースパスワードのリセット
- 接続プーリングの設定
- SSLの設定プレーンテキスト接続を拒否デフォルトでは有効
- ディスクサイズの設定
- ネットワーク制限と禁止の適用
- Reset the database password
- Configure connection pooling
- Configure SSL: Reject plan-text connections (by default they are enabled)
- Configure Disk size
- Apply network restrictions and bans
## API設定
## API Configuration
> [!TIP]
> **このデータには、`https://supabase.com/dashboard/project/<project-id>/settings/api`のようなリンクからアクセスできます**
> **This data can be accessed from a link like `https://supabase.com/dashboard/project/<project-id>/settings/api`**
プロジェクトのsupabase APIにアクセスするためのURLは次のようになります`https://jnanozjdybtpqgcwhdiz.supabase.co`
プロジェクトの supabase API にアクセスする URL は次のようになります:`https://jnanozjdybtpqgcwhdiz.supabase.co`
### anon APIキー
### anon api keys
また、**anon APIキー**`role: "anon"`を生成します:`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpuYW5vemRyb2J0cHFnY3doZGl6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTQ5OTI3MTksImV4cCI6MjAzMDU2ODcxOX0.sRN0iMGM5J741pXav7UxeChyqBE9_Z-T0tLA9Zehvqk`、これはアプリケーションが私たちの例で公開されたAPIキーに連絡するために使用する必要があります。
また、`role: "anon"` のような **anon API key** を生成します。例`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpuYW5vemRyb2J0cHFnY3doZGl6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTQ5OTI3MTksImV4cCI6MjAzMDU2ODcxOX0.sRN0iMGM5J741pXav7UxeChyqBE9_Z-T0tLA9Zehvqk`アプリケーションはこの API key を使用して API にアクセスする必要があります。
このAPIに連絡するためのAPI RESTは[**ドキュメント**](https://supabase.com/docs/reference/self-hosting-auth/returns-the-configuration-settings-for-the-gotrue-server)で見つけることができますが、最も興味深いエンドポイントは次のとおりです:
この API に接続するための REST API は [**docs**](https://supabase.com/docs/reference/self-hosting-auth/returns-the-configuration-settings-for-the-gotrue-server) で確認できますが、最も興味深いエンドポイントは次のとおりです:
<details>
<summary>サインアップ (/auth/v1/signup)</summary>
<summary>Signup (/auth/v1/signup)</summary>
```
POST /auth/v1/signup HTTP/2
Host: id.io.net
@@ -99,61 +99,171 @@ Priority: u=1, i
```
</details>
クライアントが付与されたサブドメインを使用してsupabaseを利用していることを発見した場合会社のサブドメインが彼らのsupabaseサブドメインにCNAMEを持つ可能性があります、**supabase APIを使用して新しいアカウントを作成する**ことを試みることができます。
So, whenever you discover a client using supabase with the subdomain they were granted (it's possible that a subdomain of the company has a CNAME over their supabase subdomain), you might try to **create a new account in the platform using the supabase API**.
### secret / service_role APIキー
### シークレット / service_role APIキー
**`role: "service_role"`**を持つ秘密のAPIキーも生成されます。このAPIキーは、**Row Level Security**をバイパスできるため、秘密にしておく必要があります。
A secret API key will also be generated with **`role: "service_role"`**. This API key should be secret because it will be able to bypass **Row Level Security**.
APIキーは次のようになります: `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpuYW5vemRyb2J0cHFnY3doZGl6Iiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTcxNDk5MjcxOSwiZXhwIjoyMDMwNTY4NzE5fQ.0a8fHGp3N_GiPq0y0dwfs06ywd-zhTwsm486Tha7354`
The API key looks like this: `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpuYW5vemRyb2J0cHFnY3doZGl6Iiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTcxNDk5MjcxOSwiZXhwIjoyMDMwNTY4NzE5fQ.0a8fHGp3N_GiPq0y0dwfs06ywd-zhTwsm486Tha7354`
### JWT Secret
### JWTシークレット
**JWT Secret**も生成され、アプリケーションが**カスタムJWTトークンを作成および署名**できるようになります。
A **JWT Secret** will also be generate so the application can **create and sign custom JWT tokens**.
## 認証
### サインアップ
> [!TIP]
> **デフォルト**では、supabase**新しいユーザーがプロジェクトにアカウントを作成する**ことを許可します。
> **デフォルトでは** supabase は前述の API エンドポイントを使用して、**新しいユーザーがアカウントを作成すること**を許可します。
ただし、これらの新しいアカウントは、デフォルトで**メールアドレスを確認する必要があります**。メールアドレスを確認せずにログインできるようにするには、**「匿名サインインを許可」**を有効にすることができます。これにより、**予期しないデータ**にアクセスできる可能性があります(彼らは`public`および`authenticated`の役割を取得します)。\
これは非常に悪いアイデアです。なぜなら、supabaseはアクティブユーザーごとに料金を請求するため、人々がユーザーを作成してログインし、supabaseがそれに対して料金を請求する可能性があるからです
However, these new accounts, by default, **will need to validate their email address** to be able to login into the account. It's possible to enable **「匿名サインインを許可」** to allow people to login without verifying their email address. This could grant access to **unexpected data** (they get the roles `public` and `authenticated`).\
This is a very bad idea because supabase charges per active user so people could create users and login and supabase will charge for those:
<figure><img src="../images/image (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
### パスワードとセッション
#### Auth: サーバー側のサインアップ制御
最小パスワード長(デフォルト)、要件(デフォルトではなし)を指定し、漏洩したパスワードの使用を禁止することが可能です。\
デフォルトの要件は弱いため、**要件を改善することをお勧めします**。
Hiding the signup button in the frontend is not enough. If the **Auth server still allows signups**, an attacker can call the API directly with the public `anon` key and create arbitrary users.
- ユーザーセッション: ユーザーセッションの動作を構成することが可能ですタイムアウト、ユーザーごとに1セッション...
- ボットおよび悪用保護: Captchaを有効にすることが可能です。
Quick test (from an unauthenticated client):
```bash
curl -X POST \
-H "apikey: <SUPABASE_ANON_KEY>" \
-H "Authorization: Bearer <SUPABASE_ANON_KEY>" \
-H "Content-Type: application/json" \
-d '{"email":"attacker@example.com","password":"Sup3rStr0ng!"}' \
https://<PROJECT_REF>.supabase.co/auth/v1/signup
```
Expected hardening:
- Disable email/password signups in the Dashboard: Authentication → Providers → Email → Disable sign ups (invite-only), or set the equivalent GoTrue setting.
- Verify the API now returns 4xx to the previous call and no new user is created.
- If you rely on invites or SSO, ensure all other providers are disabled unless explicitly needed.
### SMTP設定
## RLS and Views: Write bypass via PostgREST
メールを送信するためのSMTPを設定することが可能です。
Using a Postgres VIEW to “hide” sensitive columns and exposing it via PostgREST can change how privileges are evaluated. In PostgreSQL:
- Ordinary views execute with the privileges of the view owner by default (definer semantics). In PG ≥15 you can opt into `security_invoker`.
- Row Level Security (RLS) applies on base tables. Table owners bypass RLS unless `FORCE ROW LEVEL SECURITY` is set on the table.
- Updatable views can accept INSERT/UPDATE/DELETE that are then applied to the base table. Without `WITH CHECK OPTION`, writes that dont match the view predicate may still succeed.
### 高度な設定
Risk pattern observed in the wild:
- A reduced-column view is exposed through Supabase REST and granted to `anon`/`authenticated`.
- PostgREST allows DML on the updatable view and the operation is evaluated with the view owners privileges, effectively bypassing the intended RLS policies on the base table.
- Result: low-privileged clients can mass-edit rows (e.g., profile bios/avatars) they should not be able to modify.
- アクセストークンの有効期限を設定デフォルトは3600
- 潜在的に侵害されたリフレッシュトークンを検出して取り消すように設定し、タイムアウトを設定
- MFA: ユーザーごとに同時に登録できるMFA要素の数を指定デフォルトは10
- 最大直接データベース接続: 認証に使用される接続の最大数デフォルトは10
- 最大リクエスト期間: 認証リクエストが持続できる最大時間デフォルトは10秒
Illustrative write via view (attempted from a public client):
```bash
curl -X PATCH \
-H "apikey: <SUPABASE_ANON_KEY>" \
-H "Authorization: Bearer <SUPABASE_ANON_KEY>" \
-H "Content-Type: application/json" \
-H "Prefer: return=representation" \
-d '{"bio":"pwned","avatar_url":"https://i.example/pwn.png"}' \
"https://<PROJECT_REF>.supabase.co/rest/v1/users_view?id=eq.<victim_user_id>"
```
ビューと RLS のハードニングチェックリスト:
- ベーステーブルを公開する場合は、明示的で最小権限の付与と正確な RLS ポリシーを優先する。
- どうしてもビューを公開する必要がある場合:
- 更新不可にする(例: 式/結合 を含める)か、すべての信頼できないロールに対してビューへの `INSERT/UPDATE/DELETE` を拒否する。
- 呼び出し元の権限がオーナーの権限ではなく使用されるように `ALTER VIEW <v> SET (security_invoker = on)` を適用する。
- ベーステーブルでは `ALTER TABLE <t> FORCE ROW LEVEL SECURITY;` を使用し、オーナーであっても RLS の適用対象とする。
- 更新可能なビュー経由で書き込みを許可する場合、`WITH [LOCAL|CASCADED] CHECK OPTION` とベーステーブル側の補完的な RLS を追加して、許可された行のみが書き込まれ/変更されることを保証する。
- Supabase では、end-to-end の挙動をテストで検証していない限り、ビューに対して `anon`/`authenticated` に書き込み権限を付与しない。
## ストレージ
検出のヒント:
- `anon``authenticated` のテストユーザーから、公開されているすべてのテーブル/ビューに対してすべての CRUD 操作を試みる。拒否されるべき箇所で書き込みが成功した場合、それは設定ミスを示す。
### OpenAPI駆動の CRUD プロービング (anon/auth ロールから)
PostgREST は OpenAPI ドキュメントを公開しており、それを使ってすべての REST リソースを列挙し、低権限ロールから許可された操作を自動的にプローブすることができる。
OpenAPI を取得するpublic anon key でも動作する):
```bash
curl -s https://<PROJECT_REF>.supabase.co/rest/v1/ \
-H "apikey: <SUPABASE_ANON_KEY>" \
-H "Authorization: Bearer <SUPABASE_ANON_KEY>" \
-H "Accept: application/openapi+json" | jq '.paths | keys[]'
```
プローブパターン(例):
- 単一行を読み取るRLS によって 401/403/200 を想定):
```bash
curl -s "https://<PROJECT_REF>.supabase.co/rest/v1/<table>?select=*&limit=1" \
-H "apikey: <SUPABASE_ANON_KEY>" \
-H "Authorization: Bearer <SUPABASE_ANON_KEY>"
```
- テスト用の UPDATE はブロックされています(テスト中にデータを変更しないよう、存在しない filter を使用してください):
```bash
curl -i -X PATCH \
-H "apikey: <SUPABASE_ANON_KEY>" \
-H "Authorization: Bearer <SUPABASE_ANON_KEY>" \
-H "Content-Type: application/json" \
-H "Prefer: return=minimal" \
-d '{"__probe":true}' \
"https://<PROJECT_REF>.supabase.co/rest/v1/<table_or_view>?id=eq.00000000-0000-0000-0000-000000000000"
```
- テストの INSERT はブロックされています:
```bash
curl -i -X POST \
-H "apikey: <SUPABASE_ANON_KEY>" \
-H "Authorization: Bearer <SUPABASE_ANON_KEY>" \
-H "Content-Type: application/json" \
-H "Prefer: return=minimal" \
-d '{"__probe":true}' \
"https://<PROJECT_REF>.supabase.co/rest/v1/<table_or_view>"
```
- DELETE のテストはブロックされています:
```bash
curl -i -X DELETE \
-H "apikey: <SUPABASE_ANON_KEY>" \
-H "Authorization: Bearer <SUPABASE_ANON_KEY>" \
"https://<PROJECT_REF>.supabase.co/rest/v1/<table_or_view>?id=eq.00000000-0000-0000-0000-000000000000"
```
Recommendations:
- 以前のプローブを `anon` と最小限の `authenticated` ユーザの両方で自動化し、回帰を検出するために CI に組み込む。
- 公開されている table/view/function はすべて第一級のサーフェスとして扱う。view が基底テーブルと同じ RLS のポスチャを“継承”すると仮定しない。
### Passwords & sessions
最小パスワード長(デフォルト)、要件(デフォルトではなし)、および leaked passwords の使用を禁止する設定が可能です。\
デフォルトの要件は弱いため、**要件を強化することを推奨します**。
- User Sessions: ユーザーセッションの動作(タイムアウト、ユーザーごとに 1 セッションなど)を設定可能です。
- Bot and Abuse Protection: Captcha を有効にできます。
### SMTP Settings
メール送信のための SMTP を設定可能です。
### Advanced Settings
- access tokens の有効期限を設定する(デフォルト 3600
- 潜在的に侵害された refresh tokens を検出して取り消すよう設定およびタイムアウトを設定する
- MFA: ユーザーごとに同時に登録できる MFA 要素数を指定する(デフォルト 10
- Max Direct Database Connections: 認証に使用される最大接続数(デフォルト 10
- Max Request Duration: Auth リクエストが許容される最大時間(デフォルト 10 秒)
## Storage
> [!TIP]
> Supabase**ファイルを保存**、URLを介してアクセス可能にますS3バケットを使用します)。
> Supabase**ファイルを保存**、URL 経由でアクセス可能にできますS3 バケットを使用)。
- アップロードファイルサイズの限を設定(デフォルト50MB
- S3接続は次のようなURLで提供されます: `https://jnanozjdybtpqgcwhdiz.supabase.co/storage/v1/s3`
- `access key ID`(例: `a37d96544d82ba90057e0e06131d0a7b`)と`secret access key`(例: `58420818223133077c2cec6712a4f909aec93b4daeedae205aa8e30d5a860628`)で構成される**S3アクセスキーを要求**することが可能です。
- アップロードファイルサイズの限を設定する(デフォルト 50MB
- S3 接続は次のような URL で提供されます: `https://jnanozjdybtpqgcwhdiz.supabase.co/storage/v1/s3`
- S3 access key を **リクエスト** でき、`access key ID`(例: `a37d96544d82ba90057e0e06131d0a7b`)と `secret access key`(例: `58420818223133077c2cec6712a4f909aec93b4daeedae205aa8e30d5a860628`)で構成されす。
## エッジ関数
## Edge Functions
supabaseに**秘密を保存する**ことも可能で、これは**エッジ関数によってアクセス可能**です(ウェブから作成および削除できますが、その値に直接アクセスすることはできません)。
supabase にも **secrets を保存** でき、それらは **edge functions からアクセス可能** ですWeb から作成削除できるが、値を直接参照することはできません)。
## References
- [Building Hacker Communities: Bug Bounty Village, getDiscloseds Supabase Misconfig, and the LHE Squad (Ep. 133) YouTube](https://youtu.be/NI-eXMlXma4)
- [Critical Thinking Podcast Episode 133 page](https://www.criticalthinkingpodcast.io/episode-133-building-hacker-communities-bug-bounty-village-getdisclosed-and-the-lhe-squad/)
- [Supabase: Row Level Security (RLS)](https://supabase.com/docs/guides/auth/row-level-security)
- [PostgreSQL: Row Security Policies](https://www.postgresql.org/docs/current/ddl-rowsecurity.html)
- [PostgreSQL: CREATE VIEW (security_invoker, check option)](https://www.postgresql.org/docs/current/sql-createview.html)
- [PostgREST: OpenAPI documentation](https://postgrest.org/en/stable/references/api.html#openapi-documentation)
{{#include ../banners/hacktricks-training.md}}