mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-25 17:16:00 +03:00
[GH-ISSUE #1451] v0.8.1 CSRF errors when trying to submit POST requests #3882
Labels
No labels
expected: maybe someday
expected: next release
expected: release after next
expected: unlikely unless contributed
good first ticket
help wanted
pull-request
scope: all users
scope: windows users
size: easy
size: hard
size: medium
size: medium
status: backlog
status: blocked
status: done
status: idea-phase
status: needs followup
status: wip
status: wontfix
touches: API/CLI/Spec
touches: configuration
touches: data/schema/architecture
touches: dependencies/packaging
touches: docs
touches: js
touches: views/replayers/html/css
why: correctness
why: functionality
why: performance
why: security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ArchiveBox#3882
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ethitter on GitHub (Jun 7, 2024).
Original GitHub issue: https://github.com/ArchiveBox/ArchiveBox/issues/1451
Describe the bug
Attempting to generate an API key triggers an error, both via admin UI and API endpoint.
Steps to reproduce
Admin UI:
/admin/api/apitoken/add/API:
POSTrequest to/api/v1/auth/get_api_token, passing valid user credentials in request bodyScreenshots or log output
Admin UI:
API:
ArchiveBox version
@topperge commented on GitHub (Jun 10, 2024):
Just adding a comment that I'm getting the same problem with the same errors
@pirate commented on GitHub (Jun 10, 2024):
Sorry guys
:devis under heavy active work right now, might be broken a bit as I work on the new schemas. Stick with the tagged:0.8.0-rcor:stablefor now.@Write commented on GitHub (Aug 30, 2024):
I can't seems to find any 0.8.x tag available and /admin/api/apitoken/add/ endpoint doesn't seems to exist in :stable ? Or maybe i'm just doing something wrong
@pirate commented on GitHub (Aug 30, 2024):
:devwas updated yesterday, it's still under active development but should be able to pull and run it now! Just make sure to back up any existing data before updating.I'll also push a
:0.8.2-rctag (equivalent to:dev) right now.@Write commented on GitHub (Aug 30, 2024):
Thanks it works now.
I still can't use the API endpoint but I'm guessing that's because it's in heavy developement.
It doesn't matter if I add the API key either as "token" in the header or in the body of the request I always get
{"detail": "CSRF check Failed"}%
Upon reading this : https://github.com/ArchiveBox/ArchiveBox/blob/dev/archivebox/api/auth.py
I also tried adding ?api_key as param and also adding X-ArchiveBox-API-Key as header to no avail.
Another thing : Weirdly, you can't use ALLOWED_HOSTS=* as adding API Key via the admin panel will throw a csrf error. Manually adding your host make it works fine. I recommend adding yourhost,localhost to allow the healthcheck to work.
@pirate commented on GitHub (Aug 31, 2024):
You need to set
CSRF_TRUSTED_ORIGINS=https://archivebox.example.com(CSRF_TRUSTED_ORIGINS=http://localhost& 127.0.01 are auto included in v0.8.2). It's a new stricter requirement in Django >=v4.0, they don't allow * anymore. The docs will be updated to mention this when v0.8 is released, I'm also creating a new dedicated docs page for the REST API.https://github.com/ArchiveBox/ArchiveBox/pull/1498/files#diff-b627cf6681c8f031fa16213db7f26ff256144856eea7c614691c357728317dc6R100
https://docs.djangoproject.com/en/5.1/ref/csrf/
Also you should pull 0.8.2, 0.8.1 is already far behind the latest build 😁
@Write commented on GitHub (Aug 31, 2024):
Thanks for your fast reply.
I'm on 0.8.2-rc indeed, I still can't get API to accept my domain, even after adding CSRF_TRUSTED_ORIGINS
@pirate commented on GitHub (Sep 6, 2024):
I made a lot of changes to the auth and CSRF in the latest v0.8.3-rc pre-release.
Can you give it a try? https://github.com/ArchiveBox/ArchiveBox/releases/tag/v0.8.3-rc
The API endpoints are now CSRF exempt, but as a result they also dont accept cookies, you have to add a Bearer/auth header or query parameter to use the API. (the /api/v1/docs endpoint explains how)
Comment back if you still encounter any trouble and I'll reopen the ticket!