Fix CSRF failure when saving layout; rename plugin to NetBox-Floorplaner

Read the CSRF token from a rendered {% csrf_token %} instead of the
cookie, which may be HttpOnly or use a custom name. Set the plugin
author to Claude and bump the version to 0.1.1 (busts static cache).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-11-04 12:47:34 +01:00
1 parent b8f2e5155e
commit 6b47b0fd5b
4 files changed
+13 -9

No files matched your search

@@ -144,6 +144,10 @@
buildDom() {
this.root.classList.add(this.edit ? 'fp-edit' : 'fp-view');
this.root.tabIndex = 0;
// The template renders {% csrf_token %} into the root; the cookie may be
// unavailable (CSRF_COOKIE_HTTPONLY, custom cookie name), so prefer this.
const tokenInput = this.root.querySelector('input[name=csrfmiddlewaretoken]');
this.csrfToken = tokenInput ? tokenInput.value : getCookie('csrftoken');
this.root.innerHTML = '';
this.toolbar = html('div', { class: 'fp-toolbar' });
@@ -410,7 +414,7 @@
const resp = await fetch(this.cfg.api.layout, {
method: 'PUT',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-CSRFToken': getCookie('csrftoken') },
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-CSRFToken': this.csrfToken },
body: JSON.stringify(this.serialize()),
});
const data = await resp.json().catch(() => ({}));