0
0

axiosでCSRF対策

Posted at

axiosでCSRF対策

色々やったがまた403出るようになったので備忘録

ヘッダにX-CSRFTOKENとCookieにcsrftokenを追加してあげると回避できた
axiosじゃない場合はわからん

example
    deleteLog: function(id){
      const config = {
        responseType: "application/json",
      };
      const url = "hoge";
      axios.defaults.xsrfCookieName = 'csrftoken' //CSRF対策
      axios.defaults.xsrfHeaderName = "X-CSRFTOKEN" // CSRF対策
      const res = axios
        .post(url,
        {},
        config)
        .then((res) => {
          // 処理
        })
        .catch((e) => {
          console.error(e);
        });
    },
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