Skip to content

Commit 7ae01ca

Browse files
committed
fix #303: use csrftoken from hidden input field
1 parent b40523f commit 7ae01ca

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

client/admin-sortable2.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,13 @@ class ListSortable extends SortableBase {
150150
}
151151

152152
public get headers(): Headers {
153-
const value = `; ${document.cookie}`;
154-
const parts = value.split('; csrftoken=');
155-
const csrfToken = parts.length === 2 ? parts[1].split(';').shift() : null;
156153
const headers = new Headers();
157154
headers.append('Accept', 'application/json');
158155
headers.append('Content-Type', 'application/json');
159-
if (csrfToken) {
160-
headers.append('X-CSRFToken', csrfToken);
156+
157+
const inputElement = this.tableBody.closest('form')?.querySelector('input[name="csrfmiddlewaretoken"]') as HTMLInputElement;
158+
if (inputElement) {
159+
headers.append('X-CSRFToken', inputElement.value);
161160
}
162161
return headers;
163162
}

0 commit comments

Comments
 (0)