Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Lisk Validator does not validate integer formats when provided as number #8915

Closed
Tracked by #7226
shuse2 opened this issue Aug 30, 2023 · 1 comment
Closed
Tracked by #7226

Comments

@shuse2
Copy link
Collaborator

shuse2 commented Aug 30, 2023

Description

Unresolved in PR #8743.

The fix corrects the problem that was reported and the format of numbers with the type integer are correctly validated.
However, the opposite is now a problem—the format of a “number” of type string is not correctly validated.

One example of where this happens in the code is shown in the figure below (more examples may exist).
https://github.com/LiskHQ/lisk-sdk/blob/release/6.0.0/framework/src/modules/reward/schemas.ts#L59-L69

This behavior can be confirmed with the following tests.

   describe('uint32_string', () => {
		const uint32StringSchema = {
			...baseSchema,
			properties: {
				height: {
					type: 'string',
					format: 'uint32',
				},
			},
		};

		it('should validate a correct uint32', () => {
			expect(() => validator.validate(uint32StringSchema, { height: "8" })).not.toThrow();
		});

		it('should throw for a negative number', () => {
			expect(() => validator.validate(uint32StringSchema, { height: "-1" })).toThrow();
		});

		it('should throw when the number is too big', () => {
			expect(() => validator.validate(uint32StringSchema, { height: "4294967296" })).toThrow();
		});
	});

Which version(s) does this affect? (Environment, OS, etc...)

6.0.0-beta.7

@bobanm
Copy link
Contributor

bobanm commented Sep 4, 2023

I think this is a non-issue, as in SDK 32-bit numbers are always defined as integer type, and never as string type.

Instead, the solution I provided in PR #8926 fixes how 64-bit numbers are handled: always as string type, instead of integer.

@shuse2 shuse2 closed this as completed Sep 4, 2023
@shuse2 shuse2 added this to the Sprint 103 milestone Sep 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants