Fix deploy and lock down the DM route; add /invitation
All checks were successful
Deploy Palico Bot / deploy (push) Successful in 32s
All checks were successful
Deploy Palico Bot / deploy (push) Successful in 32s
- Deploy workflow: pin node:24-bookworm; install openssh-client only if missing - Auth failure limiter counts only 401s (422/404 no longer lock out clients) - trust proxy configurable (WEB_TRUSTED_PROXIES), never "true" - DM route: loopback connections only, dedicated NOTIFICATIONS_API_KEY, 503 when unset - Jukebox: no polling without a key, stop on 401 - /invitation: posts the temporary invite message after checking the link - Stop tracking storage/library.json; README describes the real deployment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3655b1ad74
commit
6895d20459
16 changed files with 554 additions and 99 deletions
|
|
@ -4,7 +4,11 @@ import { rateLimit } from "express-rate-limit";
|
|||
import multer from "multer";
|
||||
import path from "path";
|
||||
import { config } from "../config.js";
|
||||
import { authMiddleware } from "./middlewares/auth.js";
|
||||
import {
|
||||
authMiddleware,
|
||||
createBearerAuth,
|
||||
localOnly,
|
||||
} from "./middlewares/auth.js";
|
||||
import { libraryRouter } from "./routes/library.js";
|
||||
import { notificationsRouter } from "./routes/notifications.js";
|
||||
import { playerRouter } from "./routes/player.js";
|
||||
|
|
@ -17,12 +21,33 @@ import {
|
|||
|
||||
const PUBLIC_DIR = path.join(process.cwd(), "public");
|
||||
|
||||
function startWebServer(dependencies) {
|
||||
ensureStorageLayout();
|
||||
cleanupTemporaryFiles();
|
||||
function apiRateLimit(options) {
|
||||
return rateLimit({
|
||||
standardHeaders: "draft-8",
|
||||
legacyHeaders: false,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
// Freine les essais de clé : seules les réponses 401 comptent. Les autres erreurs (404 d'un
|
||||
// utilisateur inconnu, 422 messages privés fermés…) ne doivent pas bloquer un client authentifié.
|
||||
function authFailureLimit() {
|
||||
return apiRateLimit({
|
||||
windowMs: 15 * 60_000,
|
||||
limit: 20,
|
||||
skipSuccessfulRequests: true,
|
||||
requestWasSuccessful: (_req, res) => res.statusCode !== 401,
|
||||
message: { error: "Trop de tentatives d'authentification" },
|
||||
});
|
||||
}
|
||||
|
||||
function createApp(
|
||||
dependencies,
|
||||
{ notificationsApiKey = config.notificationsApiKey } = {}
|
||||
) {
|
||||
const app = express();
|
||||
app.disable("x-powered-by");
|
||||
app.set("trust proxy", config.webTrustedProxies);
|
||||
app.use(helmet());
|
||||
app.use(express.json({ limit: "32kb" }));
|
||||
|
||||
|
|
@ -30,49 +55,29 @@ function startWebServer(dependencies) {
|
|||
res.json({ status: "ok" });
|
||||
});
|
||||
|
||||
// Messages privés pour les applications de confiance : connexions locales uniquement,
|
||||
// avec leur propre clé (pas celle du jukebox, connue de ses utilisateurs).
|
||||
app.use(
|
||||
"/api/notifications",
|
||||
localOnly,
|
||||
apiRateLimit({ windowMs: 60_000, limit: 60 }),
|
||||
authFailureLimit(),
|
||||
createBearerAuth(() => notificationsApiKey),
|
||||
notificationsRouter(dependencies)
|
||||
);
|
||||
|
||||
const apiRouter = express.Router();
|
||||
apiRouter.use(
|
||||
rateLimit({
|
||||
windowMs: 60_000,
|
||||
limit: 120,
|
||||
standardHeaders: "draft-8",
|
||||
legacyHeaders: false,
|
||||
})
|
||||
);
|
||||
apiRouter.use(
|
||||
rateLimit({
|
||||
windowMs: 15 * 60_000,
|
||||
limit: 20,
|
||||
skipSuccessfulRequests: true,
|
||||
standardHeaders: "draft-8",
|
||||
legacyHeaders: false,
|
||||
message: { error: "Trop de tentatives d'authentification" },
|
||||
})
|
||||
);
|
||||
apiRouter.use(apiRateLimit({ windowMs: 60_000, limit: 120 }));
|
||||
apiRouter.use(authFailureLimit());
|
||||
apiRouter.use(authMiddleware);
|
||||
apiRouter.use(
|
||||
"/uploads",
|
||||
rateLimit({
|
||||
windowMs: 15 * 60_000,
|
||||
limit: 10,
|
||||
standardHeaders: "draft-8",
|
||||
legacyHeaders: false,
|
||||
}),
|
||||
apiRateLimit({ windowMs: 15 * 60_000, limit: 10 }),
|
||||
uploadsRouter(dependencies)
|
||||
);
|
||||
apiRouter.use("/queue", queueRouter(dependencies));
|
||||
apiRouter.use("/library", libraryRouter(dependencies));
|
||||
apiRouter.use("/player", playerRouter(dependencies));
|
||||
apiRouter.use(
|
||||
"/notifications",
|
||||
rateLimit({
|
||||
windowMs: 60_000,
|
||||
limit: 60,
|
||||
standardHeaders: "draft-8",
|
||||
legacyHeaders: false,
|
||||
}),
|
||||
notificationsRouter(dependencies)
|
||||
);
|
||||
|
||||
app.use("/api", apiRouter);
|
||||
app.get(["/jukebox", "/jukebox/"], (_req, res) =>
|
||||
|
|
@ -93,6 +98,14 @@ function startWebServer(dependencies) {
|
|||
});
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
function startWebServer(dependencies) {
|
||||
ensureStorageLayout();
|
||||
cleanupTemporaryFiles();
|
||||
|
||||
const app = createApp(dependencies);
|
||||
const port = Number(process.env.PORT || config.webServerPort || 3000);
|
||||
|
||||
const server = app.listen(port, () => {
|
||||
|
|
@ -104,4 +117,4 @@ function startWebServer(dependencies) {
|
|||
return { app, server };
|
||||
}
|
||||
|
||||
export { startWebServer };
|
||||
export { createApp, startWebServer };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue