Added comment.

This commit is contained in:
Andrew Lalis 2023-07-23 20:01:02 -04:00
parent 7af0708c40
commit 0e3881dcac
1 changed files with 3 additions and 0 deletions

View File

@ -60,12 +60,15 @@ void handleVisitorLog(ref HttpRequestContext ctx) {
return; return;
} }
string remoteAddress = ctx.request.getHeader("X-Forwarded-For"); string remoteAddress = ctx.request.getHeader("X-Forwarded-For");
// If the user has sent another log within the last minute, block this one.
LogEntry[] recentLogsByThisAddress = getRecentLogEntriesByRemoteAddress(remoteAddress); LogEntry[] recentLogsByThisAddress = getRecentLogEntriesByRemoteAddress(remoteAddress);
SysTime now = Clock.currTime(); SysTime now = Clock.currTime();
if (recentLogsByThisAddress.length > 0 && now - recentLogsByThisAddress[0].createdAt < minutes(1)) { if (recentLogsByThisAddress.length > 0 && now - recentLogsByThisAddress[0].createdAt < minutes(1)) {
ctx.response.setStatus(HttpStatus.TOO_MANY_REQUESTS); ctx.response.setStatus(HttpStatus.TOO_MANY_REQUESTS);
return; return;
} }
insertLogEntry(remoteAddress, name, message); insertLogEntry(remoteAddress, name, message);
} }