"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DevConsoleLocalhostMiddleware = void 0;
exports.isLocalhostDirect = isLocalhostDirect;
const __ΩRecord = ['K', 'T', 'Record', 'l\'e#"Rb!b"Pde"!N#!w#y'];
const http_1 = require("@deepkit/http");
const middleware_1 = require("../http/middleware");
const HttpForbiddenError = (0, http_1.createHttpError)(403, 'Forbidden');
function isLocalhostDirect(request) {
    // Reject if request was forwarded through a reverse proxy
    if (request.headers['x-forwarded-for'] || request.headers['x-real-ip']) {
        return false;
    }
    const ip = request.socket.remoteAddress ?? '';
    const normalized = ip.startsWith('::ffff:') ? ip.slice(7) : ip;
    return normalized === '127.0.0.1' || ip === '::1';
}
isLocalhostDirect.__type = ['remoteAddress', 'socket', () => __ΩRecord, 'headers', 'request', 'isLocalhostDirect', 'PPP&4!8M4"&P&&F-Jo##4$M2%)/&'];
class DevConsoleLocalhostMiddleware extends middleware_1.HttpMiddleware {
    handle(request, _response) {
        if (!isLocalhostDirect(request)) {
            throw new HttpForbiddenError();
        }
    }
}
exports.DevConsoleLocalhostMiddleware = DevConsoleLocalhostMiddleware;
DevConsoleLocalhostMiddleware.__type = [() => middleware_1.HttpMiddleware, () => http_1.HttpRequest, 'request', () => http_1.HttpResponse, '_response', 'handle', 'DevConsoleLocalhostMiddleware', 'P7!PP7"2#P7$2%"0&5w\''];
//# sourceMappingURL=devconsole.middleware.js.map