Forbidden (403)
CSRF验证失败。请求中止。 p>
引用>Help Reason given for failure: CSRF token missing or incorrect. In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure: Your browser is accepting cookies. The view function passes a request to the template's render method. In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL. If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data. The form has a valid CSRF token. After logging in in another browser tab or hitting the back button after a login, you may need to reload the page with the form, because the token is rotated after a login. You're seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed. You can customize this page using the CSRF_FAILURE_VIEW setting.
** cross-site Request Forgery (CSRF) vulnerability. ** is a malicious exploit of a website. Although it sounds like cross-site scripting (XSS), it is very different from XSS, which exploits a trusted user within a site, while CSRF exploits a trusted site by impersonating a Request from a trusted user. CSRF attacks tend to be less prevalent (and therefore have relatively few resources to defend against) and harder to defend against than XSS attacks, and are therefore considered more dangerous than XSS attacks
can understand strong> :
the attacker steal your identity, in the name of your sending malicious request, the request for server is perfectly legal, but finished the attacker’s expectation of an operation, such as in the name of your email, send messages, to steal your account, add a system administrator, or even to buy goods, virtual currency transfer, etc.Django’s protection against CSRF is to place an auto-generated token in each generated form to determine whether a POST request is coming from the same site
solution one:
Use the Django template here. Use the TemplateTag to add CSRF tokens. Add {% crrf_token %}
in the from form
# index.html ... <form method="post"> <div > <input name="username" placeholder="username"><br> <input name="password" placeholder="password"><br> <div > <button type='submit' id='btn'>提交</button> </div> </div> {% csrf_token %} </form> ...
again, refresh the page and resubmit the form to access
normally
solution two:
simply ignores this check and comments CSRF in the Settings. Py of the project
MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', #'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ]
CSRF (cross-site request forgery)
CSRF specific see: p>
https://www.cnblogs.com/liuqingzheng/p/9505044.html
Read More:
- Forbidden (403) CSRF verification failed. Request aborted. – Django
- egg.js The frame post request reported an error of invalid CSRF token security verification, which has been solved
- [nodejs] error request aborted after request routing in post mode
- Flash + Vue uses Axios to obtain server data, and reports error: “request aborted”
- Nextcloud error: “access forbidden CSRF check failed”
- Error 1: Vue quickly clicks the route to jump. Error: uncaught (in promise) error: request aborted
- 8、Forbidden (CSRF token missing or incorrect.): /register/
- Flask Request an extension before_request after_request errorhandler
- Bug:Install Microsoft Visual C++ 2008 Redistributable (x86) Failed Installation aborted, Result=1603
- In the HTML page request Ajax times 400 error, solve Yii submit post form 400 error, and Ajax post request 400 problem (example code)
- Hash verification failed for CDH5.8.2 installation
- Verification of your TeamViewer version failed
- Solve host key verification failed [valid]
- Jenkins SVN error Server SSL certificate verification failed: issuer is not trusted
- 【Oracle】IMP-00010: not a valid export file, header failed verification
- IIS “Bad Request – Request Too Long. HTTP Error 400. The size of the request headers is too long.”
- svn: E230001: Server SSL certificate verification failed: certificate issued
- Host key verification failed. fatal: Could not read from remote repository.
- Bad Request – Request Too Long. HTTP Error 400. The size of the request headers is too long
- How to remove the message “Membership credential verification failed.” displayed in the Event Log