0
0

【学習メモ】API GatewayのCross-origin resource sharing (CORS)とは

Posted at

Cross-origin resource sharing (CORS)とは

MDNから抜粋ですが

Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than its own from which a browser should permit loading resources. CORS also relies on a mechanism by which browsers make a "preflight" request to the server hosting the cross-origin resource, in order to check that the server will permit the actual request. In that preflight, the browser sends headers that indicate the HTTP method and headers that will be used in the actual request.

概要だけ訳すと
・オリジン:ドメイン、スキーマ、ポート
・クロスオリジン:自サーバーと違う「ドメイン、スキーマ、ポート」
・サーバーが違うオリジンからのリクエストのHTTPヘッダーを見て、「あなたはこのサーバーのリソースをもらっていいか」を判断する仕組み

API GatewayのCross-origin resource sharing (CORS)とは

API Gatewayで構築されたREST APIはCORSの機能を持っており、異なる「ドメイン、スキーマ、ポート」からのリクエストを処理するかの判断したり、

AWSから抜粋ですが

別のドメイン (例: example.com から amazondomains.com へ)
別のサブドメイン (例: example.com から petstore.example.com へ)
別のポート (例: example.com から example.com:10777 へ)
別のプロトコル (例: https://example.com から http://example.com へ)

さらに、メソッドで判断するのも可能

GET、HEAD、および POST のリクエストのみを許可
POST メソッドリクエストの場合、Origin ヘッダーを含める必要がある

参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0