Filter data: URLs before creating posts

- Prevent data: URLs from being sent to backend (crash browsers)
- Only send properly uploaded asset URLs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
SocioWire 2026-01-04 22:43:56 +00:00
parent e5f9cad7df
commit 2014e3434d
2 changed files with 43 additions and 35 deletions

View File

@ -13,7 +13,7 @@ import { parseAuthError } from "./authErrors";
const AuthCtx = createContext(null);
const KC_URL = (import.meta?.env?.VITE_KC_URL || "https://www.sociowire.com/auth").replace(/\/+$/, "");
const KC_URL = (import.meta?.env?.VITE_KC_URL || "https://auth.sociowire.com").replace(/\/+$/, "");
const KC_REALM = import.meta?.env?.VITE_KC_REALM || "sociowire";
const KC_CLIENT_ID = import.meta?.env?.VITE_KC_CLIENT_ID || "sociowire-frontend";
const KC_SSO_ENABLED = (import.meta?.env?.VITE_KC_SSO || "true") !== "false";
@ -278,6 +278,7 @@ export function AuthProvider({ children }) {
}
async function ensureFreshSession(existing) {
try {
if (!existing?.access_token) return { ok: false, reason: "no_access_token" };
const exp = jwtExpSeconds(existing.access_token);
@ -308,12 +309,16 @@ export function AuthProvider({ children }) {
setError("");
// Update email verification state from backend
await refreshProfile(existing.access_token);
await refreshProfile(existing.access_token).catch(() => {});
return { ok: true };
}
return { ok: false, reason: `whoami_${w.status}`, detail: w.text || "" };
} catch (err) {
console.error("[Auth] ensureFreshSession error:", err);
return { ok: false, reason: "exception", detail: err?.message || "" };
}
}
function scheduleAutoRefresh() {
@ -362,8 +367,8 @@ export function AuthProvider({ children }) {
setError("");
setLastInfo("");
// Clear tokens from old/wrong issuer (keep any sociowire.com tokens)
clearBadTokens("sociowire.com");
// Clear tokens from old/wrong issuer - must be from auth.sociowire.com now
clearBadTokens("auth.sociowire.com");
const saved = loadAuth();
if (!saved?.access_token) {
@ -668,7 +673,7 @@ export function AuthProvider({ children }) {
});
}
const onStorage = (e) => {
if (e.key === "sociowire:auth") restore();
if (e.key === "sociowire:auth") restore().catch(() => setAnon(""));
};
window.addEventListener("storage", onStorage);
return () => window.removeEventListener("storage", onStorage);

View File

@ -1390,14 +1390,17 @@ export default function MapView({
payload.published_at = draftPublishedAt.trim();
}
const mediaCandidates = draftMediaUrls.filter(Boolean);
// Filter out data: URLs - they crash browsers and bloat the DB
const mediaCandidates = draftMediaUrls.filter(
(url) => url && !url.startsWith("data:")
);
if (mediaCandidates.length > 0) {
payload.image_small = mediaCandidates[0];
payload.image_medium = mediaCandidates[1] || mediaCandidates[0];
payload.image_large =
mediaCandidates[2] || mediaCandidates[1] || mediaCandidates[0];
payload.media_urls = mediaCandidates;
} else if (useCustomImage && draftImage.trim()) {
} else if (useCustomImage && draftImage.trim() && !draftImage.trim().startsWith("data:")) {
const fallback = draftImage.trim();
payload.image_small = fallback;
payload.image_medium = fallback;