Skip to content

Commit a7189dd

Browse files
committed
sachen
1 parent b666244 commit a7189dd

File tree

19 files changed

+1664
-427
lines changed

19 files changed

+1664
-427
lines changed

.env.local.backup

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
POSTGRES_URL="postgres://postgres.hxijjvnsrxynegthasmh:pcE680j67rhFfDRr@aws-0-eu-central-1.pooler.supabase.com:6543/postgres?sslmode=require&supa=base-pooler.x"
2+
POSTGRES_USER="postgres"
3+
POSTGRES_HOST="db.hxijjvnsrxynegthasmh.supabase.co"
4+
SUPABASE_JWT_SECRET="998Vo+CP+u2rNnH6fv9w4KWGb+8I1P9bXjrM2tKiFE5YcIlQ1Tr+NBNPNGw1de2drhvoXX0dSZJZ84toPkxBtA=="
5+
NEXT_PUBLIC_SUPABASE_ANON_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imh4aWpqdm5zcnh5bmVndGhhc21oIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDc3Mzk5NDcsImV4cCI6MjA2MzMxNTk0N30.zWILyiJA1K5L0w2rynsWqhMVU6jySaal5lC9IBO05bc"
6+
POSTGRES_PRISMA_URL="postgres://postgres.hxijjvnsrxynegthasmh:pcE680j67rhFfDRr@aws-0-eu-central-1.pooler.supabase.com:6543/postgres?sslmode=require&supa=base-pooler.x"
7+
POSTGRES_PASSWORD="pcE680j67rhFfDRr"
8+
POSTGRES_DATABASE="postgres"
9+
SUPABASE_URL="https://hxijjvnsrxynegthasmh.supabase.co"
10+
NEXT_PUBLIC_SUPABASE_URL="https://hxijjvnsrxynegthasmh.supabase.co"
11+
SUPABASE_SERVICE_ROLE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imh4aWpqdm5zcnh5bmVndGhhc21oIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0NzczOTk0NywiZXhwIjoyMDYzMzE1OTQ3fQ.poV3TJW7eJULdQ_yYHhygUPbEMYW-SSrIVWSsnRXRAk"
12+
POSTGRES_URL_NON_POOLING="postgres://postgres.hxijjvnsrxynegthasmh:pcE680j67rhFfDRr@aws-0-eu-central-1.pooler.supabase.com:5432/postgres?sslmode=require"
13+
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/1326548524657016842/rJrqRnK7lZQKKh_kzT2bz_rjBx6T0BDz8vym4SVeMt-sLXl4PaMycrYuM8pbbr1JNpSm"
14+
NEXT_PUBLIC_SITE_URL = "https://orange-engine-q6gpjxwwqg9h9pw5-3001.app.github.dev"
15+
16+
AUTHORIZED_ADMINS=Sparths,sparths,f8adc96a-496f-412b-af15-20bd3cd66b3c
17+
NEXT_PUBLIC_AUTHORIZED_ADMINS=Sparths,sparths

SECURITY_CHECKLIST.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Security Implementation Checklist
2+
3+
## Files to Update
4+
- [ ] Copy secure-token.ts content from artifact
5+
- [ ] Copy sanitization.ts content from artifact
6+
- [ ] Copy rate-limiter-config.ts content from artifact
7+
- [ ] Copy csrf-protection.ts content from artifact
8+
- [ ] Copy session-manager.ts content from artifact
9+
- [ ] Copy security-headers.ts content from artifact
10+
- [ ] Update middleware.ts
11+
- [ ] Create use-csrf.ts hook
12+
- [ ] Create csrf API route
13+
- [ ] Create session API route
14+
15+
## API Routes to Update
16+
- [ ] /app/api/admin/verify/route.tsx
17+
- [ ] /app/api/project-requests/route.tsx
18+
- [ ] /app/api/users/route.tsx
19+
- [ ] /app/api/comments/route.tsx
20+
- [ ] /app/api/ratings/route.tsx
21+
- [ ] /app/api/badges/route.tsx
22+
23+
## Frontend Components to Update
24+
- [ ] CommentSection.tsx - Add CSRF headers
25+
- [ ] RatingSystem.tsx - Add CSRF headers
26+
- [ ] AuthContext.tsx - Remove localStorage usage
27+
- [ ] UserProjectRequests.tsx - Add CSRF headers
28+
- [ ] ProfileForm.tsx - Add CSRF headers
29+
30+
## Testing
31+
- [ ] Test rate limiting
32+
- [ ] Test CSRF protection
33+
- [ ] Test XSS prevention
34+
- [ ] Test admin authentication
35+
- [ ] Test session management
36+
37+
## Deployment
38+
- [ ] Set environment variables in production
39+
- [ ] Enable HTTPS
40+
- [ ] Test all features in production
41+
- [ ] Monitor security logs

app/api/admin/verify/route.tsx

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { NextResponse } from "next/server";
22
import { createClient } from '@supabase/supabase-js';
3+
import { createSecureAdminToken, verifySecureAdminToken } from '@/lib/security/secure-token';
4+
import { sanitizeInput } from '@/lib/security/sanitization';
35

46
// Admin verification with service role
57
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!;
@@ -19,11 +21,6 @@ const getAuthorizedAdmins = (): string[] => {
1921
return adminList.split(',').map(admin => admin.trim());
2022
};
2123

22-
// Input sanitization
23-
const sanitizeInput = (input: string): string => {
24-
return input.replace(/[<>]/g, '').trim();
25-
};
26-
2724
export async function POST(request: Request) {
2825
try {
2926
const body = await request.json();
@@ -52,15 +49,8 @@ export async function POST(request: Request) {
5249
if (authorizedAdmins.includes(sanitizedUserId)) {
5350
console.log("User found in direct admin list:", sanitizedUserId);
5451

55-
// Create admin session token for subsequent requests
56-
const adminSession = {
57-
userId: sanitizedUserId,
58-
timestamp: Date.now(),
59-
verified: true,
60-
isAdmin: true
61-
};
62-
63-
const adminToken = Buffer.from(JSON.stringify(adminSession)).toString('base64');
52+
// Create secure admin session token
53+
const adminToken = createSecureAdminToken(sanitizedUserId);
6454

6555
return NextResponse.json({
6656
success: true,
@@ -108,15 +98,8 @@ export async function POST(request: Request) {
10898
if (isAdmin) {
10999
console.log("User verified as admin");
110100

111-
// Create admin session token for subsequent requests
112-
const adminSession = {
113-
userId: sanitizedUserId,
114-
timestamp: Date.now(),
115-
verified: true,
116-
isAdmin: true
117-
};
118-
119-
const adminToken = Buffer.from(JSON.stringify(adminSession)).toString('base64');
101+
// Create secure admin session token
102+
const adminToken = createSecureAdminToken(sanitizedUserId);
120103

121104
return NextResponse.json({
122105
success: true,
@@ -160,12 +143,26 @@ export async function POST(request: Request) {
160143
}
161144
}
162145

163-
// Optional: GET method to check current admin status
146+
// GET method to check current admin status
164147
export async function GET(request: Request) {
165148
try {
166149
const { searchParams } = new URL(request.url);
167150
const userId = searchParams.get("userId");
168151

152+
// Check for admin token in Authorization header
153+
const authHeader = request.headers.get('authorization');
154+
if (authHeader && authHeader.startsWith('Bearer ')) {
155+
const token = authHeader.substring(7);
156+
const verification = verifySecureAdminToken(token);
157+
158+
if (verification.isValid) {
159+
return NextResponse.json({
160+
isAdmin: true,
161+
userId: verification.userId
162+
});
163+
}
164+
}
165+
169166
if (!userId) {
170167
return NextResponse.json(
171168
{ error: "User ID is required" },

app/api/auth/csrf/route.tsx

Whitespace-only changes.

app/api/auth/session/route.tsx

Whitespace-only changes.

0 commit comments

Comments
 (0)