fix: pass CSRF token to API-rendered item cards

The explore and hashtag API controllers rendered ap-item-card.njk with
csrfToken: "" causing Like/Boost/Save buttons in tab panels to fail
with 403 Invalid CSRF token. Now generates a proper token from the
session via getToken().
This commit is contained in:
Ricardo
2026-02-28 17:31:54 +01:00
parent 35f1f13096
commit ecba2b5748
4 changed files with 8 additions and 5 deletions
+2 -1
View File
@@ -188,10 +188,11 @@ export function exploreApiController(mountPath) {
} }
// Render each card server-side // Render each card server-side
const csrfToken = getToken(request.session);
const templateData = { const templateData = {
...response.locals, ...response.locals,
mountPath, mountPath,
csrfToken: "", csrfToken,
interactionMap: {}, interactionMap: {},
}; };
+3 -1
View File
@@ -17,6 +17,7 @@
*/ */
import { validateHashtag, mapMastodonStatusToItem } from "./explore-utils.js"; import { validateHashtag, mapMastodonStatusToItem } from "./explore-utils.js";
import { getToken } from "../csrf.js";
const FETCH_TIMEOUT_MS = 10_000; const FETCH_TIMEOUT_MS = 10_000;
const PAGE_SIZE = 20; const PAGE_SIZE = 20;
@@ -183,10 +184,11 @@ export function hashtagExploreApiController(mountPath) {
); );
// Render HTML AFTER merge/dedup/paginate (don't waste CPU on discarded items) // Render HTML AFTER merge/dedup/paginate (don't waste CPU on discarded items)
const csrfToken = getToken(request.session);
const templateData = { const templateData = {
...response.locals, ...response.locals,
mountPath, mountPath,
csrfToken: "", csrfToken,
interactionMap: {}, interactionMap: {},
}; };
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "@rmdes/indiekit-endpoint-activitypub", "name": "@rmdes/indiekit-endpoint-activitypub",
"version": "2.0.0", "version": "2.1.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@rmdes/indiekit-endpoint-activitypub", "name": "@rmdes/indiekit-endpoint-activitypub",
"version": "2.0.0", "version": "2.1.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@fedify/debugger": "^2.0.0", "@fedify/debugger": "^2.0.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@rmdes/indiekit-endpoint-activitypub", "name": "@rmdes/indiekit-endpoint-activitypub",
"version": "2.1.0", "version": "2.1.1",
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.", "description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
"keywords": [ "keywords": [
"indiekit", "indiekit",