最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

security - Is having a CSRF with FastAPI any safer than not? - Stack Overflow

programmeradmin0浏览0评论

I've just read this article about Flask and using Svelte frontend with a separate API specifically the section calledFrontend Served Separately (cross-domain)

They are creating a CSRF cookie and header X-CSRFToken and I'm just built something similar using FastAPI.

Is this actually any more secure because couldn't a bad actor:

  • Get a user to click on something
  • New page calls the CSRF page and sets cookie/header cross domain
  • On post the cookie/header are set

I know I must be missing something but I am confused. The code in question is:

@app.route("/api/getcsrf", methods=["GET"])
def get_csrf():
    token = generate_csrf()
    response = jsonify({"detail": "CSRF cookie set"})
    response.headers.set("X-CSRFToken", token)
    return response
发布评论

评论列表(0)

  1. 暂无评论