From 26e49f74fe400c096e9508ba1468d300db6bc301 Mon Sep 17 00:00:00 2001
From: SenequeZ <148022515+SenequeZ@users.noreply.github.com>
Date: Mon, 9 Nov 2026 17:17:59 -0500
Subject: [PATCH] Support individual mode, multi-line connection info, and
stale tokens
- deploy token: fall back to the user id for team_id when the player
has no team (CTFd individual mode). Galvanize keys per-player
deployments by team_id, so null broke deploy/status/extend/terminate.
- view: render connection_info one entry per line, each URL its own
link. Galvanize joins several published ports with "\n"; they were
shown as one code block, or as one broken link when the first entry
was an HTTP URL.
- view: store the JWT per challenge id + category and fetch a new one
when the cached token's category no longer matches the challenge,
instead of failing with 400 "Invalid challenge" after a category edit.
- view: on a 404 from /status, reset the deploy button unless the
message says the challenge is unique. A 404 JSON body without
"unique" (or without a message) left the modal spinning or threw.
---
api/deploy.py | 4 +++-
assets/view.js | 50 +++++++++++++++++++++++++++++++-------------------
2 files changed, 34 insertions(+), 20 deletions(-)
diff --git a/api/deploy.py b/api/deploy.py
index 6516c00..15dc6c3 100644
--- a/api/deploy.py
+++ b/api/deploy.py
@@ -51,7 +51,9 @@ def post(self, args: dict):
"exp": datetime.now(tz=timezone.utc) + timedelta(minutes=180),
"iat": datetime.now(tz=timezone.utc),
"user_id": str(user.id),
- "team_id": str(team.id) if team else None,
+ # Galvanize keys per-player deployments by team_id. In CTFd's
+ # individual mode there is no team, so use the user's ID.
+ "team_id": str(team.id) if team else str(user.id),
"role": "user",
"challenge_name": challenge.name,
"category": category,
diff --git a/assets/view.js b/assets/view.js
index 2347951..75da73d 100644
--- a/assets/view.js
+++ b/assets/view.js
@@ -146,8 +146,10 @@ function displayConnectionInfo(statusData) {
const extension_time = statusData.extension_time || "30m";
const unique = statusData.unique;
- // If connection_info is a URL, make it a clickable link
- const connectionInfo = (connection_info.indexOf('http') === 0) ? `${connection_info}` : `${connection_info}`;
+ // One entry per line; HTTP URLs become clickable links
+ const connectionInfo = connection_info.split('\n').filter(line => line.trim() !== '').map(line =>
+ (line.indexOf('http') === 0) ? `${line}` : `${line}`
+ ).join('
');
let timeBoxHtml = "";
if (expiration_time) {
@@ -263,7 +265,7 @@ async function getToken(challengeId) {
throw new Error("Missing token in response");
}
- sessionStorage.setItem("jwt_" + challengeId, token);
+ sessionStorage.setItem(zyncTokenKey(challengeId), token);
return true;
} catch (err) {
showErrorMessage(
@@ -274,8 +276,13 @@ async function getToken(challengeId) {
}
}
+function zyncTokenKey(challengeId) {
+ const cat = (CTFd._internal.challenge.data && CTFd._internal.challenge.data.category) || "";
+ return "jwt_" + challengeId + "_" + cat;
+}
+
async function ensureToken(challengeId) {
- if (!sessionStorage.getItem("jwt_"+challengeId)) {
+ if (!sessionStorage.getItem(zyncTokenKey(challengeId))) {
const tokenObtained = await getToken(challengeId);
if (!tokenObtained) {
return false;
@@ -283,10 +290,17 @@ async function ensureToken(challengeId) {
}
// check JWT validity
- const token = sessionStorage.getItem("jwt_"+challengeId);
+ const token = sessionStorage.getItem(zyncTokenKey(challengeId));
const tokenParts = token.split('.');
const now = Math.ceil(Date.now() / 1000);
- if (tokenParts.length !== 3 || (JSON.parse(atob(tokenParts[1])).exp < now)) {
+ let payload = {};
+ try {
+ payload = JSON.parse(atob(tokenParts[1]));
+ } catch (e) {
+ payload = {};
+ }
+ const currentCat = (CTFd._internal.challenge.data && CTFd._internal.challenge.data.category) || "";
+ if (tokenParts.length !== 3 || payload.exp < now || (payload.category && payload.category !== currentCat)) {
const tokenObtained = await getToken(challengeId);
if (!tokenObtained) {
return false;
@@ -326,7 +340,7 @@ async function getDeploymentStatus(skipLoadingState = false) {
return;
}
- const token = sessionStorage.getItem("jwt_" + challengeId);
+ const token = sessionStorage.getItem(zyncTokenKey(challengeId));
try {
const res = await fetch(localStorage.getItem("deployer_url") + "/status", {
@@ -361,16 +375,14 @@ async function getDeploymentStatus(skipLoadingState = false) {
showErrorMessage("Attention !", "Authentification invalide");
return;
case 404:
- // check if response is empty or has json error message
- if (!res.headers.get("Content-Type")?.includes("application/json")) {
- resetDeployButton();
- return;
- }
- const data404 = await res.json();
- if (data404.message.includes("unique")) {
- // Hide deploy button if challenge is not unique
- document.querySelector(`#zync_deploy_${challengeId}`).style.display = "none";
+ if (res.headers.get("Content-Type")?.includes("application/json")) {
+ const data404 = await res.json().catch(() => ({}));
+ if (data404.message && data404.message.includes("unique")) {
+ document.querySelector(`#zync_deploy_${challengeId}`).style.display = "none";
+ return;
+ }
}
+ resetDeployButton();
return;
case 500:
const errData = await res.json();
@@ -405,7 +417,7 @@ async function deploy() {
method: "POST",
headers: {
"Content-Type": "application/json",
- "Authorization": "Bearer " + sessionStorage.getItem("jwt_" + CTFd._internal.challenge.data.id),
+ "Authorization": "Bearer " + sessionStorage.getItem(zyncTokenKey(CTFd._internal.challenge.data.id)),
},
body: JSON.stringify({
challenge_name: CTFd._internal.challenge.data.name,
@@ -474,7 +486,7 @@ async function extendInstance() {
method: "POST",
headers: {
"Content-Type": "application/json",
- "Authorization": "Bearer " + sessionStorage.getItem("jwt_" + challengeId),
+ "Authorization": "Bearer " + sessionStorage.getItem(zyncTokenKey(challengeId)),
},
});
@@ -538,7 +550,7 @@ async function delete_deployment() {
method: "POST",
headers: {
"Content-Type": "application/json",
- "Authorization": "Bearer " + sessionStorage.getItem("jwt_" + challengeId),
+ "Authorization": "Bearer " + sessionStorage.getItem(zyncTokenKey(challengeId)),
},
body: JSON.stringify({
challenge_name: challengeName,