refactor: enhance security and performance in configuration and API routes
- Update Content Security Policy (CSP) in next.config.ts to avoid `unsafe-eval` in production, improving security against XSS attacks. - Refactor API routes to enforce admin authentication and session validation, ensuring secure access to sensitive endpoints. - Optimize analytics data retrieval by using database aggregation instead of loading all records into memory, improving performance and reducing memory usage. - Implement session token creation and verification for better session management and security across the application. - Enhance error handling and input validation in various API routes to ensure robustness and prevent potential issues.
This commit is contained in:
@@ -10,8 +10,9 @@ export const apiCache = {
|
||||
if (page !== '1') keyParts.push(`page:${page}`);
|
||||
if (limit !== '50') keyParts.push(`limit:${limit}`);
|
||||
if (category) keyParts.push(`cat:${category}`);
|
||||
if (featured !== null) keyParts.push(`feat:${featured}`);
|
||||
if (published !== null) keyParts.push(`pub:${published}`);
|
||||
// Avoid cache fragmentation like `feat:undefined` when params omit the field
|
||||
if (featured != null) keyParts.push(`feat:${featured}`);
|
||||
if (published != null) keyParts.push(`pub:${published}`);
|
||||
if (difficulty) keyParts.push(`diff:${difficulty}`);
|
||||
if (search) keyParts.push(`search:${search}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user