Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions backend/secuscan/saved_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
import uuid
from typing import Any, Dict, List, Optional

from fastapi import APIRouter, HTTPException
from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel, Field, field_validator

from .auth import require_api_key
from .database import get_db

saved_views_router = APIRouter(prefix="/api/v1/saved-views", tags=["saved-views"])
saved_views_router = APIRouter(
prefix="/api/v1/saved-views",
tags=["saved-views"],
dependencies=[Depends(require_api_key)],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Route saved-view calls through the authenticated client

After this dependency is added, the existing saved-views frontend client still uses a private fetch helper that only passes signal (frontend/src/hooks/useSavedViews.ts:129-132) instead of the shared authenticated request path that adds credentials: 'include' and X-Api-Key (frontend/src/api.ts:404-415). In deployments where API_BASE is absolute, including the local preview/static path in frontend/src/api.ts:5-9, those saved-view requests no longer send the session cookie or API key, so every backend sync is treated as unavailable and the feature silently falls back to localStorage even after login.

Useful? React with 👍 / 👎.

)

_VALID_SORT_MODES = {"severity", "newest", "oldest", "target"}
_VALID_SEVERITIES = {"all", "critical", "high", "medium", "low", "info"}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export async function logoutSession(): Promise<void> {
_apiKey = null
}

function getApiKey(): string | null {
export function getApiKey(): string | null {
return _apiKey
}

Expand Down
9 changes: 8 additions & 1 deletion frontend/src/hooks/useSavedViews.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { API_BASE } from '../api'
import { API_BASE, getApiKey } from '../api'

export interface FilterPreset {
severity: string
Expand Down Expand Up @@ -126,8 +126,15 @@ async function apiFetch<T>(
init?: RequestInit,
): Promise<T | null> {
try {
const apiKey = getApiKey()
const authHeaders: Record<string, string> = apiKey ? { 'X-Api-Key': apiKey } : {}
const res = await fetch(`${API_BASE}${path}`, {
...init,
headers: {
...authHeaders,
...(init?.headers as Record<string, string> | undefined),
},
credentials: 'include',
signal: AbortSignal.timeout(8000),
})
if (!res.ok) return null
Expand Down
Loading