security: comprehensive hardening pass — CSP, CORS lockdown, CSRF strict-origin, error leak redaction, crypto visitor IDs, rate limiter fix, catalog admin guard, ESM imports, production cookie flags
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* Simulated neural processor for local dev, offline fallback, and PRD contract testing (API-11).
|
||||
* Transforms or filters incoming image buffer safely without external native dependencies.
|
||||
*/
|
||||
import { deflateSync } from 'zlib';
|
||||
export async function generateMockNeuralResult(
|
||||
imageBuffer: Buffer,
|
||||
toolId: string,
|
||||
@@ -29,7 +30,6 @@ export async function generateMockNeuralResult(
|
||||
}
|
||||
|
||||
function createSyntheticArtPng(width: number, height: number, seedText: string): Buffer {
|
||||
const zlib = require('zlib');
|
||||
const signature = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
||||
|
||||
const ihdr = Buffer.alloc(13);
|
||||
@@ -55,7 +55,7 @@ function createSyntheticArtPng(width: number, height: number, seedText: string):
|
||||
}
|
||||
}
|
||||
|
||||
const compressed = zlib.deflateSync(rawData);
|
||||
const compressed = deflateSync(rawData);
|
||||
const idatChunk = makePngChunk('IDAT', compressed);
|
||||
const iendChunk = makePngChunk('IEND', Buffer.alloc(0));
|
||||
|
||||
|
||||
@@ -18,8 +18,10 @@ export function checkRateLimits(
|
||||
ip: string,
|
||||
limits = { perVisitorPerDay: 5, perIpPerHour: 25, dailyBudgetCalls: 5000 }
|
||||
): { allowed: boolean; reason?: 'visitor_daily' | 'ip_hourly' | 'budget_exhausted'; remainingToday: number } {
|
||||
// Relax rate limits for local development, but respect explicit limits in test suites
|
||||
const isLocal = process.env.NODE_ENV !== 'test' && (ip === '127.0.0.1' || ip === '::1' || ip === 'localhost' || !ip || process.env.NODE_ENV !== 'production');
|
||||
// Relax rate limits only for loopback addresses in development; never in production or test
|
||||
const isLoopback = ip === '127.0.0.1' || ip === '::1' || ip === 'localhost';
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
const isLocal = isDev && isLoopback;
|
||||
const effectiveLimits = isLocal
|
||||
? { perVisitorPerDay: 10000, perIpPerHour: 10000, dailyBudgetCalls: 50000 }
|
||||
: limits;
|
||||
|
||||
@@ -202,10 +202,13 @@ export async function executeBackendTryIt(
|
||||
|
||||
// Inject Secret Key (PRD §7.11: Secrets never reach browser)
|
||||
const secretParam = endpoint.params.find((p) => p.isSecret || p.name === 'secretKey');
|
||||
const secretVal = process.env.API_SECRET_DEFAULT || 'abcdef';
|
||||
if (secretParam) {
|
||||
const secretVal = process.env.API_SECRET_DEFAULT;
|
||||
if (!secretVal) {
|
||||
console.warn(`[Backend API] API_SECRET_DEFAULT not configured — skipping secret injection for endpoint ${endpoint.id}`);
|
||||
}
|
||||
if (secretVal && secretParam) {
|
||||
formData.append(secretParam.name, secretVal);
|
||||
} else {
|
||||
} else if (secretVal) {
|
||||
formData.append('secretKey', secretVal);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user