Always filter sensitive data at the API/server level before sending responses to the client. Never rely on client-side filtering or assume that data not displayed in the UI is secure. Any data sent to the client should be considered public and accessible to anyone with malicious intent.
Always filter sensitive data at the API/server level before sending responses to the client. Never rely on client-side filtering or assume that data not displayed in the UI is secure. Any data sent to the client should be considered public and accessible to anyone with malicious intent.
Key principles:
app.config
) must never contain secrets or sensitive valuesExample of proper server-side filtering:
// ❌ Bad: Returning entire user entity
export default defineEventHandler(async (event) => {
const user = await db.query.users.findFirst()
return user // Contains password, internal fields, etc.
})
// ✅ Good: Return only necessary fields
export default defineEventHandler(async (event) => {
const user = await db.query.users.findFirst()
return {
id: user.id,
email: user.email,
name: user.name
// password and other sensitive fields excluded
}
})
Remember: “An API is and should always be considered as something public and accessible.” Even if sensitive data isn’t displayed in your UI, it can still be accessed by inspecting network requests or the client bundle.
Enter the URL of a public GitHub repository