fastest-validator: potential uuid validation bug

This may be a potential uuid bug in the fastest-validator or incorrect usage of the API from my part (due to lack of expertise, in which case, kindly ignore)

I have the following moleculerjs action defined in my service.

import UUID from "uuid";
...
@Action({
    rest: {
        method: "GET",
        path: "/process/:id",
    },
    params: {
        id: { type: "uuid" },
        cache: { type: "boolean", optional: true, default: true, convert: true }
    }
})
async getFlowProcess(ctx: Context<{ id: typeof UUID, cache: boolean }>): Promise<Dto<FlowProcess>> {
 const id = ctx.params.id;
 ....
}

For the below uuids

9adabada-3b4b-32eb-fd7e-c41191eefa2a
642ff728-2fb3-3e6b-f48f-0cfb94b772e2

it fails with the following error message

{
    "name": "ValidationError",
    "message": "Parameters validation error!",
    "code": 422,
    "type": "VALIDATION_ERROR",
    "data": [
        {
            "type": "uuid",
            "message": "The 'id' field must be a valid UUID.",
            "field": "id",
            "actual": "9adabada-3b4b-32eb-fd7e-c41191eefa2a",
            "nodeID": "sqc-x1-xtrm-apr-21964",
            "action": "v1.dataflow.getFlowProcess"
        }
    ]
}

I validated the correctness of this uuid on

https://www.freecodeformat.com/validate-uuid-guid.php

image

I tried to provide the uuid version property as follows and tried it with various values ranging from 0-5

   params: {
       id: { type: "uuid", version: 3 },
       cache: { type: "boolean", optional: true, default: true, convert: true }
   }

For all cases, except version: 3, i get the following error response (e.g, when I set version: 4):

{
   "name": "ValidationError",
   "message": "Parameters validation error!",
   "code": 422,
   "type": "VALIDATION_ERROR",
   "data": [
       {
           "type": "uuidVersion",
           "message": "The 'id' field must be a valid UUID version provided.",
           "field": "id",
           "expected": 4,
           "actual": 3,
           "nodeID": "machine-21528",
           "action": "v1.dataflow.getFlowProcess"
       }
   ]
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

@arun-prakash-fokus I’m going to close this issue but if you still have questions, feel free to continue here. Thanks

This is a VALID UUID, right?

Not. Reserved but not used in uuid for version 3, 4 and 5, only 8-b

Variants

@erfanium - thank you very much the explanation. I will use your proposed approach.

This does not concern fastest-validator strictly.

Nevertheless, I am adding an external link to the Apache NiFi’s Jira board so that it helps anyone who is looking for a solution related to the UUID issues with NiFi / FV / moleculerjs.

I have the hack documented here to generate valid UUIDs inside NiFi using the X-Cluster-Id-Generation-Seed header

https://issues.apache.org/jira/browse/NIFI-8669

@arun-prakash-fokus

That the UUIDs are validated as valid.

They are not valid. If you want to allow UUIDs that has unknown variant, just use this code from here. https://github.com/icebob/fastest-validator/issues/216#issuecomment-781370967