Compare commits

..

2 Commits

Author SHA1 Message Date
Zimeng Xiong 81918b00cd chore: release v0.3.1 2026-01-20 13:41:22 -08:00
Zimeng Xiong 3b384dc5fb CSRF token validation failing behind nginx proxy (#38)
Express was not configured to trust proxy headers, causing req.ip to return nginx's internal container IP instead of the actual client IP. In Docker environments, nginx can appear with different internal IPs between requests, causing the CSRF clientId to change and token validation to fail.
2026-01-20 13:39:33 -08:00
6 changed files with 21 additions and 30 deletions
+1 -1
View File
@@ -1 +1 @@
0.3.0 0.3.1
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "backend", "name": "backend",
"version": "0.3.0", "version": "0.3.1",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
+6
View File
@@ -129,6 +129,12 @@ const initializeUploadDir = async () => {
}; };
const app = express(); const app = express();
// Trust proxy headers (X-Forwarded-For, X-Real-IP) from nginx
// Required for correct client IP detection when running behind a reverse proxy
// This fixes CSRF token validation failures in Docker/K8s environments
app.set("trust proxy", 1);
const httpServer = createServer(app); const httpServer = createServer(app);
const io = new Server(httpServer, { const io = new Server(httpServer, {
cors: { cors: {
+9 -23
View File
@@ -30,9 +30,7 @@ let activeConfig: SecurityConfig = { ...defaultConfig };
* Configure security settings * Configure security settings
* @param config Partial configuration to merge with defaults * @param config Partial configuration to merge with defaults
*/ */
export const configureSecuritySettings = ( export const configureSecuritySettings = (config: Partial<SecurityConfig>): void => {
config: Partial<SecurityConfig>
): void => {
activeConfig = { ...activeConfig, ...config }; activeConfig = { ...activeConfig, ...config };
}; };
@@ -320,13 +318,10 @@ export const appStateSchema = z
.optional() .optional()
.nullable(), .nullable(),
currentItemRoundness: z currentItemRoundness: z
.union([ .object({
z.enum(["sharp", "round"]),
z.object({
type: z.enum(["round", "sharp"]), type: z.enum(["round", "sharp"]),
value: z.number().finite().min(0).max(1), value: z.number().finite().min(0).max(1),
}), })
])
.optional() .optional()
.nullable(), .nullable(),
currentItemFontSize: z currentItemFontSize: z
@@ -432,19 +427,10 @@ export const sanitizeDrawingData = (data: {
]; ];
// Dangerous URL protocols to block entirely // Dangerous URL protocols to block entirely
const dangerousProtocols = [ const dangerousProtocols = [/^javascript:/i, /^vbscript:/i, /^data:text\/html/i];
/^javascript:/i,
/^vbscript:/i,
/^data:text\/html/i,
];
// Suspicious patterns for security validation within data URLs // Suspicious patterns for security validation within data URLs
const suspiciousPatterns = [ const suspiciousPatterns = [/<script/i, /javascript:/i, /on\w+\s*=/i, /<iframe/i];
/<script/i,
/javascript:/i,
/on\w+\s*=/i,
/<iframe/i,
];
// Maximum size for dataURL (configurable, default 10MB to prevent DoS) // Maximum size for dataURL (configurable, default 10MB to prevent DoS)
const MAX_DATAURL_SIZE = activeConfig.maxDataUrlSize; const MAX_DATAURL_SIZE = activeConfig.maxDataUrlSize;
@@ -462,8 +448,8 @@ export const sanitizeDrawingData = (data: {
const normalizedValue = value.toLowerCase(); const normalizedValue = value.toLowerCase();
// First, check for dangerous protocols - block these entirely // First, check for dangerous protocols - block these entirely
const hasDangerousProtocol = dangerousProtocols.some( const hasDangerousProtocol = dangerousProtocols.some((pattern) =>
(pattern) => pattern.test(value) pattern.test(value)
); );
if (hasDangerousProtocol) { if (hasDangerousProtocol) {
@@ -479,8 +465,8 @@ export const sanitizeDrawingData = (data: {
if (isSafeImageType) { if (isSafeImageType) {
// Check for suspicious content and size limits // Check for suspicious content and size limits
const hasSuspiciousContent = suspiciousPatterns.some( const hasSuspiciousContent = suspiciousPatterns.some((pattern) =>
(pattern) => pattern.test(value) pattern.test(value)
); );
const isTooLarge = value.length > MAX_DATAURL_SIZE; const isTooLarge = value.length > MAX_DATAURL_SIZE;
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "frontend", "name": "frontend",
"private": true, "private": true,
"version": "0.3.0", "version": "0.3.1",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
-1
View File
@@ -301,7 +301,6 @@ export const Editor: React.FC = () => {
try { try {
const persistableAppState = { const persistableAppState = {
...appState,
viewBackgroundColor: appState?.viewBackgroundColor || '#ffffff', viewBackgroundColor: appState?.viewBackgroundColor || '#ffffff',
gridSize: appState?.gridSize || null, gridSize: appState?.gridSize || null,
}; };