Validate the request at the Express boundary with a Zod schema and return structured errors before using the data: ```ts import { z } from "zod"; import type { RequestHandler } from "express"; const registrationSchema = z.object({ email: z.string().email(), password: z.string().min(12).max(128), }); type RegistrationInput = z.infer<typeof registrationSchema>; export const register: RequestHandler = async (req, res, next) => { const result = registrationSchema.safeParse(req.body); if (!result....
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill typescript-security --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Typescript Security?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-typescript-security-53a45d90)More formats (shields.io, HTML) on the badges page.
Validate the request at the Express boundary with a Zod schema and return structured errors before using the data:
```ts
import { z } from "zod";
import type { RequestHandler } from "express";
const registrationSchema = z.object({
email: z.string().email(),
password: z.string().min(12).max(128),
});
type RegistrationInput = z.infer<typeof registrationSchema>;
export const register: RequestHandler = async (req, res, next) => {
const result = registrationSchema.safeParse(req.body);
if (!result.success) {
res.status(400).json({
error: "invalid_request",
details: result.error.flatten().fieldErrors,
});
return;
}
const input: RegistrationInput = result.data;
try {
// Hash with Argon2id before persistence; never store input.password.
await createUser({
email: input.email,
passwordHash: await argon2.hash(input.password, {
type: argon2.argon2id,
}),
});
res.status(201).json({ ok: true });
} catch (error: unknown) {
next(error);
}
};
```
Keep the schema at the untrusted boundary, avoid trusting TypeScript casts, and ensure the endpoint has appropriate rate limiting and generic duplicate-account errors.
Is this your skill, or is something wrong with this listing? . Author removals are honored within 72 hours.
No comments yet. Be the first to comment!