Skip to content

Commit 6fa7777

Browse files
authored
fix/df-973: Ensures no unicode in email (#1161)
* Ensures no unicode in email * Extra validation to save-and-exit email * Model and engine bumps
1 parent b3d80a9 commit 6fa7777

4 files changed

Lines changed: 44 additions & 36 deletions

File tree

package-lock.json

Lines changed: 15 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
"license": "SEE LICENSE IN LICENSE",
4747
"dependencies": {
4848
"@aws-sdk/client-sns": "^3.997.0",
49-
"@defra/forms-engine-plugin": "^4.5.6",
50-
"@defra/forms-model": "^3.0.635",
49+
"@defra/forms-engine-plugin": "^4.6.0",
50+
"@defra/forms-model": "^3.0.644",
5151
"@defra/hapi-tracing": "^1.30.0",
5252
"@elastic/ecs-pino-format": "^1.5.0",
5353
"@hapi/boom": "^10.0.1",

src/server/models/save-and-exit.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { crumbSchema, stateSchema } from '@defra/forms-engine-plugin/schema.js'
22
import {
33
ControllerPath,
44
SecurityQuestionsEnum,
5+
UNICODE_EMAIL_ERROR_MESSAGE,
6+
preventUnicodeInEmail,
57
slugSchema
68
} from '@defra/forms-model'
79
import Joi from 'joi'
@@ -243,11 +245,17 @@ export const paramsSchema = Joi.object()
243245
export const payloadSchema = Joi.object()
244246
.keys({
245247
crumb: crumbSchema,
246-
email: Joi.string().email().required().messages({
247-
'string.email':
248-
'Enter an email address in the correct format, for example, hello@example.com',
249-
'*': 'Enter an email address'
250-
}),
248+
email: Joi.string()
249+
.trim()
250+
.email()
251+
.custom((value, helpers) => preventUnicodeInEmail(value, helpers))
252+
.required()
253+
.messages({
254+
'string.email':
255+
'Enter an email address in the correct format, for example, hello@example.com',
256+
'string.unicode': UNICODE_EMAIL_ERROR_MESSAGE,
257+
'*': 'Enter an email address'
258+
}),
251259
emailConfirmation: Joi.string()
252260
.valid(Joi.ref('email'))
253261
.required()

src/server/plugins/SummaryPageWithConfirmationEmailController.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,26 @@ import {
1414
type FormRequestPayload,
1515
type FormResponseToolkit
1616
} from '@defra/forms-engine-plugin/types'
17-
import { type GovukField } from '@defra/forms-model'
18-
import Joi from 'joi'
17+
import { preventUnicodeInEmail, type GovukField } from '@defra/forms-model'
18+
import Joi, { type CustomHelpers } from 'joi'
1919

2020
export const CONFIRMATION_EMAIL_FIELD_NAME = 'userConfirmationEmailAddress'
2121

2222
const schema = Joi.object().keys({
2323
crumb: crumbSchema,
2424
action: actionSchema,
25-
userConfirmationEmailAddress: Joi.string().email().allow('').messages({
26-
'*': 'Enter an email address in the correct format'
27-
})
25+
userConfirmationEmailAddress: Joi.string()
26+
.email()
27+
.trim()
28+
.custom((value, helpers: CustomHelpers<string>) =>
29+
preventUnicodeInEmail(value, helpers)
30+
)
31+
.allow('')
32+
.messages({
33+
'*': 'Enter an email address in the correct format',
34+
'string.unicode':
35+
'The email address you entered includes invalid characters, for example, long dashes'
36+
})
2837
})
2938

3039
export class SummaryPageWithConfirmationEmailController extends SummaryPageController {

0 commit comments

Comments
 (0)