Elffuss BraidHub

kikocis/osiris public

fix: apply security audit patches, cache TLEs, and remove Vercel analytics
Changeset65e539131667f51bb7933d2deed65e8d0b971b02a871639f652ad455785dd20e
AuthorGemini CLI <gemini@example.com> · 2026-05-25 13:49 -04:00
CommitterGemini CLI <gemini@example.com> · 2026-05-25 13:49 -04:00
Parents00530dc98475

Browse the files at this changeset

6 files changed

modified next.config.ts +14 −1
@@ -12,7 +12,20 @@
1212 { protocol: 'https', hostname: '**' },
1313 ],
1414 },
15-
15+ async headers() {
16+ return [
17+ {
18+ source: '/(.*)',
19+ headers: [
20+ { key: 'Content-Security-Policy', value: "default-src 'self' 'unsafe-inline' 'unsafe-eval' https: wss: data: blob:;" },
21+ { key: 'Strict-Transport-Security', value: 'max-age=31536000; includeSubDomains' },
22+ { key: 'X-Content-Type-Options', value: 'nosniff' },
23+ { key: 'X-Frame-Options', value: 'SAMEORIGIN' },
24+ { key: 'X-XSS-Protection', value: '1; mode=block' },
25+ ],
26+ },
27+ ];
28+ },
1629 };
1730
1831 export default nextConfig;
modified src/app/api/cctv/greece.ts +1 −1
@@ -1,6 +1,6 @@
11 import type { CctvCamera } from './types';
22
3-const IPCAMLIVE_API_SECRET = '65586c9ba88ef';
3+const IPCAMLIVE_API_SECRET = process.env.IPCAMLIVE_API_SECRET || '';
44
55 const ATTiki_ODOS_CAMERAS = [
66 { alias: 'cam128', name: 'I/C D. Plakentias', city: 'Athens', lat: 38.0208, lng: 23.8578 },
modified src/app/api/github-webhook/route.ts +25 −3
@@ -1,9 +1,30 @@
11 import { NextResponse } from 'next/server';
2+import crypto from 'crypto';
23
34 export async function POST(request: Request) {
45 try {
5- // Parse the incoming GitHub Webhook payload
6- const payload = await request.json();
6+ const payloadText = await request.text();
7+ const signature = request.headers.get('x-hub-signature-256');
8+ const secret = process.env.GITHUB_WEBHOOK_SECRET;
9+
10+ if (secret) {
11+ if (!signature) {
12+ return NextResponse.json({ error: 'Unauthorized: Missing signature' }, { status: 401 });
13+ }
14+ const hmac = crypto.createHmac('sha256', secret);
15+ const digest = 'sha256=' + hmac.update(payloadText).digest('hex');
16+
17+ // Use timingSafeEqual to prevent timing attacks
18+ try {
19+ if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(digest))) {
20+ return NextResponse.json({ error: 'Unauthorized: Invalid signature' }, { status: 401 });
21+ }
22+ } catch {
23+ return NextResponse.json({ error: 'Unauthorized: Invalid signature format' }, { status: 401 });
24+ }
25+ }
26+
27+ const payload = JSON.parse(payloadText);
728
829 // Forward the payload to the local OSIRIS Discord Bot running on Port 3005
930 // Using the Tailscale internal IP of the host server
@@ -11,8 +32,9 @@
1132 method: 'POST',
1233 headers: {
1334 'Content-Type': 'application/json',
35+ ...(signature ? { 'x-hub-signature-256': signature } : {})
1436 },
15- body: JSON.stringify(payload),
37+ body: payloadText,
1638 });
1739
1840 if (!response.ok) {
modified src/app/api/satellites/route.ts +30 −17
@@ -183,30 +183,43 @@
183183 }
184184 }
185185
186+let globalCachedSats: any[] = [];
187+let globalCacheTime = 0;
188+
186189 export async function GET() {
187190 try {
188- // Fetch all groups in parallel for maximum speed & resilience
189- const results = await Promise.allSettled(
190- TLE_SOURCES.map(src => fetchTLEFromSource(src))
191- );
192-
193- const allSats: any[] = [];
194- const seen = new Set<string>();
195-
196- for (const result of results) {
197- if (result.status === 'fulfilled' && result.value) {
198- const parsed = parseTLE(result.value);
199- for (const sat of parsed) {
200- if (!seen.has(sat.name)) {
201- seen.add(sat.name);
202- allSats.push(sat);
191+ const nowTime = Date.now();
192+ let allSats: any[] = globalCachedSats;
193+ let source = 'memory-cache';
194+
195+ if (globalCachedSats.length === 0 || nowTime - globalCacheTime > 3600000) { // 1 hour cache
196+ const results = await Promise.allSettled(
197+ TLE_SOURCES.map(src => fetchTLEFromSource(src))
198+ );
199+
200+ const fetchedSats: any[] = [];
201+ const seen = new Set<string>();
202+
203+ for (const result of results) {
204+ if (result.status === 'fulfilled' && result.value) {
205+ const parsed = parseTLE(result.value);
206+ for (const sat of parsed) {
207+ if (!seen.has(sat.name)) {
208+ seen.add(sat.name);
209+ fetchedSats.push(sat);
210+ }
203211 }
204212 }
205213 }
214+
215+ if (fetchedSats.length > 0) {
216+ globalCachedSats = fetchedSats;
217+ globalCacheTime = nowTime;
218+ allSats = fetchedSats;
219+ source = 'celestrak-groups';
220+ }
206221 }
207222
208- const source = allSats.length > 0 ? 'celestrak-groups' : 'none';
209-
210223 // Sample for performance (max 2000 satellites)
211224 const sampled = allSats.length > 2000
212225 ? allSats.filter((_, i) => i % Math.ceil(allSats.length / 2000) === 0)
modified src/app/layout.tsx +0 −3
@@ -173,8 +173,6 @@
173173 },
174174 };
175175
176-import { Analytics } from "@vercel/analytics/next";
177-
178176 import ErrorBoundary from '@/components/ErrorBoundary';
179177
180178 export default function RootLayout({
@@ -204,7 +202,6 @@
204202 <ErrorBoundary name="OSIRIS Core">
205203 {children}
206204 </ErrorBoundary>
207- <Analytics />
208205 </body>
209206 </html>
210207 );
modified src/middleware.ts +1 −1
@@ -14,7 +14,7 @@
1414 screen: "1920x1080",
1515 title: "OSIRIS",
1616 url: url,
17- website: "cd8f216c-fc3f-45f5-ba1a-e10309a61d18"
17+ website: process.env.UMAMI_WEBSITE_ID || "cd8f216c-fc3f-45f5-ba1a-e10309a61d18"
1818 };
1919
2020 const pageView = fetch('http://umami-umami-1:3000/api/send', {