Skip to content
Myr

Block a @proxy rule whose transform or narrow substituteIn the platform can't honour, and hold each refusal to its reason

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- A `@proxy(…)` rule with `transform=`, or with a `substituteIn` that does not name the bare `header` target (`["header:authorization"]`, `[query]`), now shows `block: true`. 611 swaps the placeholder into any request header and computes no credential, so showing such a rule unblocked would let the value land in a header the schema never allowed. This is the rule `ruleOf` already stated ("blocked rather than widened") and applied to `approval` and `rules=`. A `substituteIn` that names `header` stays unblocked: the platform's swap stays inside it. - Tests: `proxy.env.schema` gains `NARROW_TOKEN` (header:authorization only, blocked), `CLIENT_SECRET` (header plus a body field, not blocked) and `REGISTRY_TOKEN` (an http-basic transform, blocked), through both parsers; red by assertion before the change. - Tests: each refused fixture now carries its reason and the refusal test asserts it, so a fixture that failed to parse can no longer pass as an import refusal. `infer-required.env.schema` gains varlock's `FN_VALUE` case (a function value is required under `@defaultRequired=infer`).

authored by oscabriel · committed by oscabriel · parent b398ac5 · Browse files · 5 files+123 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+123 added−6 removed

  • tests:+103 added−3 removed
  • other:+20 added−3 removed

5 files+123 added−6 removed

modified:packages/visibility/src/env-shape.ts+20 added-3 removed
69 unmodified lines
70 : Option.none();71};7273/**74 * Whether the platform's swap, the placeholder in any request header, stays75 * where the rule lets the value go: varlock's default (any header), or a76 * `substituteIn` that names `header` among its targets. A rule that allows77 * only some headers (`header:authorization`), the query or a body field78 * would see the value land where it never allowed it.79 */80const swapsInsideTargets = (args: ParsedArgs): boolean =>81 Option.match(namedArg(args, "substituteIn"), {82 onNone: () => true,83 onSome: (targets) =>84 Option.exists(textsOf(targets), (each) => each.includes("header")),85 });8687/**88 * One `@proxy(…)` rule: its hosts in order, and the path, method and89 * `block` that narrow it. None when it names no host as text (a host only90 * the environment decides gets no value). A rule the platform cannot honour91 * exactly is blocked rather than widened: one that waits on an `approval`,78 * carries `rules` for other paths, or has a path or method that is not79 * text.92 * carries `rules` for other paths, computes its credential with a93 * `transform`, keeps the value out of some headers (`substituteIn`), or has94 * a path or method that is not text.95 */96const ruleOf = (args: ParsedArgs): Option.Option<Proxy> =>97 Option.flatMap(Option.flatMap(namedArg(args, "domain"), textsOf), (hosts) => {98 const domains = Array.filter(hosts, (host) => host !== "");
11 unmodified lines
110 const exact =111 (Option.isNone(path) || Predicate.isString(path.value)) &&112 (Option.isNone(method) || Option.isSome(methods)) &&113 Option.isNone(namedArg(args, "approval")) &&99 Option.isNone(namedArg(args, "rules"));114 Option.isNone(namedArg(args, "rules")) &&115 Option.isNone(namedArg(args, "transform")) &&116 swapsInsideTargets(args);117118 if (Option.isSome(path) && Predicate.isString(path.value)) {119 rule.path = path.value;120 }
306 unmodified lines
modified:packages/visibility/test/fixtures/env/cases.ts+91 added-2 removed
136 unmodified lines
137 key: "CACHE_DIR",138 },139 { decorators: [], key: "EMPTY_STRING", value: "" },140 { decorators: [], key: "UNSET" },141 { decorators: [], key: "FN_VALUE", value: "eq(1, 1)" },142 {143 decorators: [{ name: "sensitive", value: true }],144 key: "SESSION_SECRET",145 },
10 unmodified lines
156 "@defaultRequired=infer requires an item with a value, and @defaultSensitive=false keeps unmarked items public",157 view: {158 imports: [],159 // required-decorators.test.ts, "@defaultRequired=infer will infer based159 // on if a value is present": STATIC_VALUE required; EMPTY, UNDEFINED160 // and EMPTY_STRING not; OVERRIDE_REQUIRED and OVERRIDE_OPTIONAL win.160 // on if a value is present": STATIC_VALUE and FN_VALUE required;161 // EMPTY, UNDEFINED and EMPTY_STRING not; OVERRIDE_REQUIRED and162 // OVERRIDE_OPTIONAL win.163 // sensitive-decorator.test.ts, "static @defaultSensitive=false": TRUE164 // sensitive, DEFAULT not.165 items: [166 {
11 unmodified lines
178 tags: [],179 },180 { key: "EMPTY_STRING", required: false, sensitive: false, tags: [] },181 { key: "UNSET", required: false, sensitive: false, tags: [] },182 { key: "FN_VALUE", required: true, sensitive: false, tags: [] },183 { key: "SESSION_SECRET", required: false, sensitive: true, tags: [] },184 { key: "ADMIN_EMAIL", required: true, sensitive: false, tags: [] },185 { key: "REGION", required: false, sensitive: false, tags: [] },186 ],
253 unmodified lines
440 { name: "proxy", value: "passthrough" },441 ],442 key: "LEGACY_TOKEN",443 },444 {445 decorators: [446 {447 name: "proxy",448 value: {449 named: [450 { key: "domain", value: "api.example.invalid" },451 { key: "substituteIn", value: ["header:authorization"] },452 ],453 positional: [],454 },455 },456 ],457 key: "NARROW_TOKEN",458 },459 {460 decorators: [461 {462 name: "proxy",463 value: {464 named: [465 { key: "domain", value: "oauth.example.invalid" },466 { key: "path", value: "/oauth/token" },467 {468 key: "substituteIn",469 value: ["header", "body:client_secret"],470 },471 ],472 positional: [],473 },474 },475 ],476 key: "CLIENT_SECRET",477 },478 {479 decorators: [480 {481 name: "proxy",482 value: {483 named: [484 { key: "domain", value: "registry.example.invalid" },485 {486 key: "transform",487 value: {488 named: [{ key: "scheme", value: "http-basic" }],489 positional: [],490 },491 },492 ],493 positional: [],494 },495 },496 ],497 key: "REGISTRY_TOKEN",498 },499 ],500 },501 text: proxy,502 title:
56 unmodified lines
559 sensitive: true,560 tags: [],561 },562 { key: "LEGACY_TOKEN", required: false, sensitive: true, tags: [] },563 // guides/proxy/rules.mdx, "Substitution surface": varlock swaps564 // into any header by default; the platform does the same, so a565 // rule that allows only `header:authorization` would be widened,566 // and one that names `header` among its targets is not.567 {568 key: "NARROW_TOKEN",569 proxy: { block: true, domains: ["api.example.invalid"] },570 required: false,571 sensitive: true,572 tags: [],573 },574 {575 key: "CLIENT_SECRET",576 proxy: { domains: ["oauth.example.invalid"], path: "/oauth/token" },577 required: false,578 sensitive: true,579 tags: [],580 },581 // guides/proxy/rules.mdx, "Request transforms": the credential is582 // computed at the wire, which the platform does not do.583 {584 key: "REGISTRY_TOKEN",585 proxy: { block: true, domains: ["registry.example.invalid"] },586 required: false,587 sensitive: true,588 tags: [],589 },590 ],591 },592 },593 {
168 unmodified lines
762 readonly title: string;763 readonly file: RepoPath;764 readonly text: string;765 readonly parsed: ParsedEnvSchema;766 readonly reason: string;767}768769/** `API_KEY=` under a header that imports `path`, as the parser reads it. */770const importing = (path: string): ParsedEnvSchema => ({
5 unmodified lines
776export const refused: readonly RefusedFixture[] = [777 {778 file: RepoPath.make("home-import/.env.schema"),779 parsed: importing("~/.env.shared"),780 reason: "imports ~/.env.shared, outside the repo",781 text: homeImport,782 title: "an import from the home folder",783 },784 {785 file: RepoPath.make("absolute-import/.env.schema"),786 parsed: importing("/etc/datekit/.env.schema"),787 reason: "imports /etc/datekit/.env.schema, outside the repo",788 text: absoluteImport,789 title: "an import by absolute path",790 },791 {792 file: RepoPath.make("escaping-import/.env.schema"),793 parsed: importing("../../.env.schema"),794 reason: "imports ../../.env.schema, above the repo's root",795 text: escapingImport,796 title: "an import from above the repo's root",797 },798];
5 unmodified lines
modified:packages/visibility/test/fixtures/env/infer-required.env.schema+1 added
7 unmodified lines
8CACHE_DIR=910EMPTY_STRING=''11UNSET=undefined12FN_VALUE=eq(1, 1)1314# @sensitive15SESSION_SECRET=16
5 unmodified lines
modified:packages/visibility/test/fixtures/env/proxy.env.schema+9 added
23 unmodified lines
24SPLIT_TOKEN=2526# @sensitive @proxy=passthrough27LEGACY_TOKEN=2829# @proxy(domain="api.example.invalid", substituteIn=["header:authorization"])30NARROW_TOKEN=3132# @proxy(domain="oauth.example.invalid", path="/oauth/token", substituteIn=[header, "body:client_secret"])33CLIENT_SECRET=3435# @proxy(domain="registry.example.invalid", transform={scheme="http-basic"})36REGISTRY_TOKEN=
modified:packages/visibility/test/env-shape.test.ts+2 added-1 removed