Skip to content
Myr

leaks.ts

This file

Path

packages/protocol/test/leaks.ts

68 lines · 1.8 KiB · TypeScript

Last changed by

Merge redesign into mainoscabrielbefore adoptioncaedd21

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

lines 1–2why, one step back
1// Effect's JSON Schema leaks non-JSON values two ways: a number admitting
2// "Infinity", "-Infinity" and "NaN", and an optional key admitting `null`.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 3–21why, one step back
3import type { Schema } from "effect";
4import { Predicate } from "effect";56const NON_FINITE = new Set(["Infinity", "-Infinity", "NaN"]);78const isJsonArray = (value: Schema.Json): value is Schema.JsonArray =>9 Array.isArray(value);1011const isJsonObject = (value: Schema.Json): value is Schema.JsonObject =>12 Predicate.isObject(value);1314const children = (value: Schema.Json): readonly Schema.Json[] => {15 if (isJsonArray(value)) {16 return value;17 }1819 return isJsonObject(value) ? Object.values(value) : [];20};21

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 22why, one step back
22export const nested = (value: Schema.Json): readonly Schema.Json[] => [

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 23–68why, one step back
23 value,
24 ...children(value).flatMap(nested),25];2627const admitsNull = (schema: Schema.Json): boolean => {28 if (!isJsonObject(schema)) {29 return false;30 }3132 const { anyOf = [], oneOf = [], type = [] } = schema;3334 const members = [anyOf, oneOf].flatMap((list) =>35 isJsonArray(list) ? list : []36 );3738 return (39 type === "null" ||40 (isJsonArray(type) && type.includes("null")) ||41 members.some(admitsNull)42 );43};4445export const leaks = (schema: Schema.Json): readonly string[] =>46 nested(schema).flatMap((value) => {47 if (Predicate.isString(value) && NON_FINITE.has(value)) {48 return [`non-finite string ${value}`];49 }5051 if (!isJsonObject(value)) {52 return [];53 }5455 const { properties = {}, required = [] } = value;5657 if (!isJsonObject(properties)) {58 return [];59 }6061 const needed = new Set(isJsonArray(required) ? required : []);6263 return Object.entries(properties).flatMap(([key, property]) =>64 !needed.has(key) && admitsNull(property)65 ? [`null under optional key ${key}`]66 : []67 );68 });