Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
"dependencies": {
"svelte-kit-bot-block": "^0.0.7"
},
"devDependencies": {
"@content-collections/core": "^0.12.0",
"@content-collections/vite": "^0.2.7",
Expand Down
22 changes: 20 additions & 2 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { sequence } from '@sveltejs/kit/hooks';
import { createHandler, defaultOptions } from 'svelte-kit-bot-block';
import type { Handle } from '@sveltejs/kit';

export const handle: Handle = async ({ event, resolve }) => {
// Preload web fonts.
// Block rogue bot traffic (WordPress scanners, vulnerability probing, etc.).
// Requests matching pathname patterns return 404, all other blocks return 410.
// Run with { log: true, block: false } first to test, then enable blocking.
const botBlock = createHandler({
log: true,
block: true,
pathnames: [
...defaultOptions.pathnames,
// Block additional WordPress-related paths not covered by defaults.
/\/wp-includes/
]
});

// Preload web fonts.
const preloadFonts: Handle = async ({ event, resolve }) => {
const response = await resolve(event, {
preload: ({ type, path }) => {
if (type === 'font') {
Expand All @@ -12,3 +27,6 @@ export const handle: Handle = async ({ event, resolve }) => {
});
return response;
};

// Bot blocking should run first to reject bad requests early.
export const handle = sequence(botBlock, preloadFonts);