fix: reject load if no user agent is provided
All checks were successful
create archive with lfs / tag (push) Successful in 4s

This commit is contained in:
dusk 2025-01-16 20:39:55 +03:00
parent 3764639d11
commit c4c4cae944
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
3 changed files with 3 additions and 2 deletions

View File

@ -44,6 +44,7 @@ export const getRobotsTxt = async () => {
}
export const testUa = async (url: string, ua: string) => {
if (ua.length === 0) return false
let parsedRobots = get(cachedParsedRobots)
if (parsedRobots === null) {
parsedRobots = robotsParser(`${PUBLIC_BASE_URL}/robots.txt`, await getRobotsTxt())

View File

@ -10,7 +10,7 @@ const visitCount = writable(parseInt(existsSync(visitCountFile) ? readFileSync(v
type Visitor = { visits: number[] }
const lastVisitors = writable<Map<string, Visitor>>(new Map())
const VISITOR_EXPIRY_SECONDS = 60 * 30 // half an hour seems reasonable
const VISITOR_EXPIRY_SECONDS = 60 * 60 // an hour seems reasonable
export const incrementVisitCount = (request: Request, cookies: Cookies) => {
let currentVisitCount = get(visitCount)

View File

@ -11,7 +11,7 @@ export async function load({ request, cookies, url }) {
notifyDarkVisitors(url, request) // no await so it doesnt block load
// block any requests if the user agent is disallowed by our robots txt
if (await testUa(url.toString(), request.headers.get('user-agent') ?? "unknown user agent") === false) {
if (await testUa(url.toString(), request.headers.get('user-agent') ?? "") === false) {
throw error(403, "get a better user agent silly")
}