Files
agent/ui/src/api/api.js
T
Cédric VerstraetenandClaude Opus 5.5 c0baade8fd security: require authentication everywhere and drop the default JWT key
- JWT signing key: without AGENT_JWT_SECRET, generate a random secret on
  first start and keep it in data/config/jwt_secret (0600) instead of
  falling back to a publicly known constant. AGENT_JWT_SECRET still takes
  precedence, so deployments that share a key with Kerberos Factory are
  unchanged.
- Only tokens for the configured account are authorised, and malformed
  token claims are rejected instead of panicking.
- /ws (live view) and /file (recordings) now require a valid token. The UI
  passes it as ?token=, since browsers cannot set headers on WebSocket
  connections or <video src>; it no longer opens the socket before sign-in.
  /file no longer sends its own wildcard CORS header.
- pprof is off by default; AGENT_ENABLE_PPROF=true registers it behind auth.
- Release workflows pass tags to shell steps through quoted environment
  variables and validate them; the shared release-bump workflow is pinned
  to a commit and no longer receives inherited secrets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 22:17:28 +00:00

50 lines
1.2 KiB
JavaScript

import axios from 'axios';
import config from '../config';
const axiosBase = axios.create({
baseURL: config.API_URL,
});
axiosBase.interceptors.request.use((request) => {
request.headers.Authorization = `Bearer ${localStorage.getItem('token')}`;
return request;
});
export default axiosBase;
export function getToken() {
return localStorage.getItem('token');
}
// Browsers cannot attach an Authorization header to WebSocket connections or
// to media elements such as <video src>, so those URLs carry the token as the
// ?token= query parameter, which the agent's JWT middleware also accepts.
export function withToken(url) {
const token = getToken();
if (!token) {
return url;
}
const separator = url.includes('?') ? '&' : '?';
return `${url}${separator}token=${encodeURIComponent(token)}`;
}
export function getAPIObject(url) {
return {
url: config.API_URL + url,
headers: {
Authorization: `Bearer ${getToken()}`,
},
};
}
export function getAPI(baseURL) {
const a = axios.create({
baseURL,
});
axiosBase.interceptors.request.use((request) => {
request.headers.Authorization = `Bearer ${getToken()}`;
return request;
});
return a;
}