mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-10-28 02:15:47 -04:00
add extremely basic input validation to /api/hits endpoint
This commit is contained in:
@@ -5,9 +5,11 @@ import type { PageStats } from "../../types";
|
|||||||
const handler: NextApiHandler<PageStats> = async (req, res) => {
|
const handler: NextApiHandler<PageStats> = async (req, res) => {
|
||||||
const { slug } = req.query;
|
const { slug } = req.query;
|
||||||
|
|
||||||
if (typeof slug !== "string" || slug === "") {
|
// extremely basic input validation.
|
||||||
|
// TODO: actually check if the note exists before continuing (and allow pages other than notes).
|
||||||
|
if (typeof slug !== "string" || !new RegExp(/^notes\/([A-Za-z0-9-]+)$/i).test(slug)) {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
return res.status(400).json({ message: "Missing `slug` parameter." });
|
return res.status(400).json({ error: "Missing or invalid 'slug' parameter." });
|
||||||
}
|
}
|
||||||
|
|
||||||
// +1 hit!
|
// +1 hit!
|
||||||
|
|||||||
Reference in New Issue
Block a user