×
サイバー攻撃について
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from django.views.generic import UpdateView

from .models import Profile


class ProfileUpdateView(LoginRequiredMixin, UpdateView):
    model = Profile
    fields = ["display_name"]
    template_name = "profile/update.html"
    success_url = reverse_lazy("profile_detail")

    def get_queryset(self):
        return Profile.objects.filter(user=self.request.user)

CSRF対策だけでなく、他人のオブジェクトを変更できないよう、クエリセットを本人へ限定します。

CSRFは認証された利用者の権限を使う攻撃です。認可不備があると被害が拡大します。


11. JavaScript Fetchでの実装

11-1. CSRF Cookieを取得する