openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
51 lines (50 loc) • 1.49 kB
JavaScript
import { t as pruneMapToMaxSize } from "./map-size-BlrH_CnE.mjs";
//#region src/gateway/server/ws-connection/handshake-auth-log-limiter.ts
/** Per-key log limiter that reports suppressed auth attempts on the next emitted log. */
var HandshakeAuthLogLimiter = class {
constructor() {
this.entries = /* @__PURE__ */ new Map();
}
register(key, nowMs = Date.now()) {
const entry = this.entries.get(key);
if (!entry) {
pruneMapToMaxSize(this.entries, 255);
this.entries.set(key, {
lastLoggedAtMs: nowMs,
suppressedSinceLastLog: 0
});
return {
shouldLog: true,
suppressedSinceLastLog: 0
};
}
if (nowMs - entry.lastLoggedAtMs < 3e4) {
entry.suppressedSinceLastLog += 1;
return {
shouldLog: false,
suppressedSinceLastLog: 0
};
}
const suppressedSinceLastLog = entry.suppressedSinceLastLog;
entry.lastLoggedAtMs = nowMs;
entry.suppressedSinceLastLog = 0;
return {
shouldLog: true,
suppressedSinceLastLog
};
}
};
function buildHandshakeAuthLogKey(params) {
return [
params.reason ?? "unknown",
params.remoteAddr ?? "?",
params.client ?? "?",
params.mode ?? "?",
params.authProvided ?? "?"
].join("|");
}
function shouldLimitMissingCredentialAuthLog(params) {
return params.authProvided === "none" && (params.reason === "token_missing" || params.reason === "password_missing");
}
//#endregion
export { buildHandshakeAuthLogKey as n, shouldLimitMissingCredentialAuthLog as r, HandshakeAuthLogLimiter as t };