Skip to content

validators: isSchemaKind accepts inherited Object.prototype keys ("toString", "constructor", …), crashing the CLI with a misleading error #13

@quappefeeder

Description

@quappefeeder

Summary

isSchemaKind in packages/validators/src/schemas.ts uses the in operator, which walks the prototype chain. Inherited keys like toString, constructor, valueOf, hasOwnProperty are therefore accepted as valid schema kinds.

Reproduction

import { assertSchemaKind, validate } from "@logicsrc/validators";

assertSchemaKind("toString"); // returns "toString" — should throw Unknown schema kind
validate("toString", {});      // crashes: "schema must be object or boolean"

Via the CLI the user gets a confusing crash instead of the intended usage error:

logicsrc-validate toString fixture.json
# Error: schema must be object or boolean   <- misleading
# (expected: Unknown schema kind "toString". Expected one of: agent, …)

Cause

export function isSchemaKind(value: string): value is SchemaKind {
  return value in schemas; // "toString" in {} === true (prototype chain)
}

Suggested fix

Object.hasOwn(schemas, value) — own-property check only. PR with fix + unit tests incoming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions