diff --git a/src/presentation/forms/form-contracts.ts b/src/presentation/forms/form-contracts.ts index d424b6e3..eb9622bd 100644 --- a/src/presentation/forms/form-contracts.ts +++ b/src/presentation/forms/form-contracts.ts @@ -71,9 +71,12 @@ export function validationMessage( code: string, message: MessageResolver = defaultMessage, ): string { + // 1103/08-03. Own keys only: a server code such as `constructor` must not + // resolve to a name the frozen table inherits from Object.prototype. return message( - VALIDATION_COPY[code as keyof typeof VALIDATION_COPY] ?? - "form.validation.unknown", + Object.hasOwn(VALIDATION_COPY, code) + ? VALIDATION_COPY[code as keyof typeof VALIDATION_COPY] + : "form.validation.unknown", ); } diff --git a/tests/component/form-foundation.test.tsx b/tests/component/form-foundation.test.tsx index dc0e893e..74b427bd 100644 --- a/tests/component/form-foundation.test.tsx +++ b/tests/component/form-foundation.test.tsx @@ -596,11 +596,15 @@ describe("paired backend field codes", () => { }, ); - it("keeps the default copy for a code it does not know", () => { - expect(validationMessage("SOME_FUTURE_CODE")).toBe( - formatMessage("ko-KR", "form.validation.unknown"), - ); - }); + it.each(["SOME_FUTURE_CODE", "constructor", "toString", "__proto__", "hasOwnProperty"])( + "keeps the default copy for a code it does not know (%s)", + (code) => { + // 1103/08-03. Names inherited from Object.prototype are unknown codes too. + expect(validationMessage(code)).toBe( + formatMessage("ko-KR", "form.validation.unknown"), + ); + }, + ); }); describe("dirty navigation guard", () => {