Skip to content

Commit

Permalink
Google auth: sanitize input
Browse files Browse the repository at this point in the history
  • Loading branch information
ba1uev committed Sep 16, 2024
1 parent 86b105d commit edcaf08
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/server/auth/providers/google/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,19 @@ export const plugin: FastifyPluginCallback = async (
// e.g will match =s96-c =s128
data.picture = data.picture.replace(/=s\d+(-c)?$/, `=s${312}$1`)
}

const sanitizeInput = (x: string) =>
x.replace(/[\u0000-\u001F\u007F-\u009F]/g, '')

if (!user) {
user = await fastify.db.User.create({
fullName: data.name,
email: data.email,
avatar: data.picture,
fullName: sanitizeInput(data.name),
email: sanitizeInput(data.email),
avatar: sanitizeInput(data.picture),
roles: [appConfig.getDefaultUserRoleByEmail(data.email)],
})
} else {
await user.set({ avatar: data.picture }).save()
await user.set({ avatar: sanitizeInput(data.picture) }).save()
}

// add type to show which parameters are allowed
Expand Down

0 comments on commit edcaf08

Please sign in to comment.