fix: reject load if no user agent is provided
All checks were successful
create archive with lfs / tag (push) Successful in 4s
All checks were successful
create archive with lfs / tag (push) Successful in 4s
This commit is contained in:
parent
3764639d11
commit
c4c4cae944
@ -44,6 +44,7 @@ export const getRobotsTxt = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const testUa = async (url: string, ua: string) => {
|
export const testUa = async (url: string, ua: string) => {
|
||||||
|
if (ua.length === 0) return false
|
||||||
let parsedRobots = get(cachedParsedRobots)
|
let parsedRobots = get(cachedParsedRobots)
|
||||||
if (parsedRobots === null) {
|
if (parsedRobots === null) {
|
||||||
parsedRobots = robotsParser(`${PUBLIC_BASE_URL}/robots.txt`, await getRobotsTxt())
|
parsedRobots = robotsParser(`${PUBLIC_BASE_URL}/robots.txt`, await getRobotsTxt())
|
||||||
|
@ -10,7 +10,7 @@ const visitCount = writable(parseInt(existsSync(visitCountFile) ? readFileSync(v
|
|||||||
|
|
||||||
type Visitor = { visits: number[] }
|
type Visitor = { visits: number[] }
|
||||||
const lastVisitors = writable<Map<string, Visitor>>(new Map())
|
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) => {
|
export const incrementVisitCount = (request: Request, cookies: Cookies) => {
|
||||||
let currentVisitCount = get(visitCount)
|
let currentVisitCount = get(visitCount)
|
||||||
|
@ -11,7 +11,7 @@ export async function load({ request, cookies, url }) {
|
|||||||
notifyDarkVisitors(url, request) // no await so it doesnt block load
|
notifyDarkVisitors(url, request) // no await so it doesnt block load
|
||||||
|
|
||||||
// block any requests if the user agent is disallowed by our robots txt
|
// 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")
|
throw error(403, "get a better user agent silly")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user