Files
DarkflameServer/dDashboardServer/auth/AuthMiddleware.cpp
Aaron Kimbrell e213a7aeff feat: web dashboard and playground work
The NexusDashboard-parity dashboard (dDashboardServer) and everything built on it on the experimental branch:
accounts, characters, properties and moderation tools, permissions shared with in-game slash commands, economy
reports, World 3D and property 3D views with client scenery, scheduled events (features, vanity changes, live
events, announcements, restarts), vanity files and events, the CDClient browser, the message inspector with saved
captures, chat filter tools, community challenges, live ops, the AI moderator helper, and the server-side changes
they need.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:30:43 -05:00

23 lines
1.2 KiB
C++

#include "AuthMiddleware.h"
#include "AuthTokenHandler.h"
#include "Game.h"
#include "Logger.h"
#include "HTTPContext.h"
#include "Web.h"
bool AuthMiddleware::Process(HTTPContext& context, HTTPReply& reply) {
// Any state-changing request that doesn't carry its own Authorization header could have been sent by another
// site through the visitor's browser (a form or a text/plain fetch). Those can't set custom headers, so require
// one. This covers requests before sign-in too (login, registration, password reset); signed-in cookie requests
// are checked again in RequireAuthMiddleware.
const bool safeMethod = context.method == "GET" || context.method == "HEAD" || context.method == "OPTIONS";
if (!safeMethod && context.GetHeader("Authorization").empty() && context.GetHeader("X-Requested-With").empty()) {
LOG("Rejected %s %s without X-Requested-With (possible CSRF) from %s", context.method.c_str(), context.path.c_str(), context.clientIP.c_str());
reply.status = eHTTPStatusCode::FORBIDDEN;
reply.message = "{\"success\":false,\"error\":\"Missing X-Requested-With header\"}";
reply.contentType = eContentType::APPLICATION_JSON;
return false;
}
return AuthTokenHandler::ProcessHTTPContext(context, reply);
}