0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

APIリクエストのエンドポイントの公開範囲について

Posted at

きっかけ

JavaScriptでHTTPリクエストをする際、エンドポイント先のバックエンドの処理がprivateだとエラーになり、pulicだとjsonの返信がうまく帰ってきた。それはなぜか?

原因

結論から言うと、バックエンドのエンドポイントが「private」だとブラウザのJavaScriptから直接アクセスできないのは、CORS(Cross-Origin Resource Sharing)や認可設定によるアクセス制限が原因。
一方で「public」に設定すると、HTTPリクエストを許可するようになるため、正常にJSONレスポンスを受け取れるようにはなる。

publicにすると生じる問題

しかし、publicにすると玄関を開けっぱなしになってしまう。

対応方法は2つあるらしい。

1

public APIでも誰にでも見せてよい情報ならいい

2

CORS(Cross-Origin Resource Sharing)を設定し、許可するオリジンを制限する。

ひとまず

ここまで。
実装がうまくいかないという話だったのに、なにやら脆弱性の話になってきた。こうして私のような初心者が脆弱性を埋め込んでいくんだなぁ

次回の対応策

徳丸本に書かれていたので、そもそも積本を開こう。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?