Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Thanks — the diagnosis is right, and the field really is read on every astryx component.
A package name still reaches code the checkout controls: a local package named in astryx.theme can execute through astryx component. Restricting the config value alone therefore does not establish the trust boundary.
[Reviewed by Robohands]
| @@ -22,6 +29,13 @@ import {createRequire} from 'node:module'; | |||
|
|
|||
| const _require = createRequire(import.meta.url); | |||
There was a problem hiding this comment.
createRequire is bound here, not to cwd. Might be worth routing through module-loader.mjs instead.
There was a problem hiding this comment.
Right on both counts — bound to the CLI, and the wrong place to bind it. File specifiers now go through the shared module loader, and package specifiers use a require bound to <cwd>/package.json, with a regression that only passes when resolution is project-bound (the fixture package exists only in the fixture's node_modules).
There was a problem hiding this comment.
Still holds on current main: file specifiers use the shared importUserModule, package specifiers use a require bound to <cwd>/package.json. The regression only passes when resolution is project-bound (rebinding to the CLI's location fails it).
There was a problem hiding this comment.
Thanks — the public theme guide explicitly tells builders to use "astryx": {"theme":"./src/theme.ts"}. That setup prints the custom variant in published 0.5.0; this head drops it and warns, while astryx doctor can still report the field as wired.
The package-name check also does not complete the stated trust boundary: a package selected by the checkout executes before and after. Could you preserve the documented path behavior and add a regression proving every project-code theme load requires the same explicit opt-in?
If you'd rather talk it through with someone, we're in Discord.
[Reviewed by Robohands]
cixzhang
left a comment
There was a problem hiding this comment.
Thanks — I rechecked this unchanged head against the two prior Robohands reviews. The second corrected the first and asked to preserve the documented path setup while gating every project-code theme load. Both blockers still reproduce: the public theme guide's {"astryx":{"theme":"./src/theme.ts"}} works on current main and published 0.5.0, but this head drops its variants while astryx doctor still reports it wired; a package selected by the same checkout still executes.
Could you preserve the documented path behavior and make both path and package theme loading obey one shared safe-mode gate? If you'd rather talk it through with someone, we're in Discord.
[Reviewed by Robohands]
68f0228 to
d841cab
Compare
|
Reworked per your second review — you were right that the name check broke the documented setup without establishing the boundary. The restriction is gone: the theme guide's Regressions added for each: the documented file setup loading, project-bound package resolution (fails against a CLI-bound require), and probe-based proof that nothing executes under the gate for all three sources. Pairs with #5531, which routes the config/doc/integration loaders through the same switch; either merge order works since this reads the variable inline. |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks — I rechecked the two prior Robohands asks. This head now preserves the documented TypeScript theme path, resolves packages from the project, and keeps file, package, and ASTRYX_THEME modules unexecuted under the gate.
One security edge remains: resolve-theme.mjs:107 writes the checkout-controlled theme value directly to the terminal. A value containing a newline or ANSI control sequence can spoof the output in the untrusted-checkout mode; I reproduced both reaching the warning unchanged. Could we escape or omit that value so the notice stays one inert line? If you'd rather talk it through with someone, we're in Discord.
[Reviewed by Robohands]
| if (gateNoted) return; | ||
| gateNoted = true; | ||
| console.warn( | ||
| `⚠ theme: ASTRYX_NO_PROJECT_CODE=1 — not loading theme "${specifier}"; rendering without theme data`, |
There was a problem hiding this comment.
Could we escape or omit this checkout-controlled value? Newlines and terminal controls pass through.
There was a problem hiding this comment.
Done — added a printable() helper that replaces control characters (\p{Cc}: C0, DEL, C1) with U+FFFD before a specifier reaches the terminal, and routed all five warn sites through it (the gate notice plus the four resolve-failure warnings, which print the same checkout-controlled value). Test added: a specifier carrying an OSC sequence and a newline warns with no control character surviving into the message.
There was a problem hiding this comment.
Done: routed through printable() (control and format characters to U+FFFD), and the notice now also prints once per process. Tests at the gate-notice, file, package, and bare-name sites, each failing if the escape is removed.
d841cab to
f391b45
Compare
…mode gate
resolveTheme required through a createRequire bound to the CLI's own
location, so package themes resolved from the wrong node_modules, and it
loaded checkout files on every read command with no way to opt out.
Now file specifiers (the documented {"astryx":{"theme":"./src/theme.ts"}}
setup, unchanged by default and loaded through the same jiti path configs
use) go through the shared module loader, package specifiers resolve with
a require bound to the project, and BOTH sit behind the one safe-mode
switch: under ASTRYX_NO_PROJECT_CODE=1 no theme module (file, package, or
ASTRYX_THEME) loads at all and a one-line notice, printed once per
process, says why. Theme data is project code whichever way it is named.
Every warning that prints the configured specifier routes it through
printable(), which replaces control and format characters (Cc, Cf) with
U+FFFD, so a checkout-controlled value cannot write escape sequences,
newlines, or bidi overrides to the operator's terminal.
The variable is read inline so this change stands alone; it is the same
switch the module loader's broader gate reads.
f391b45 to
cb5aaef
Compare
|
Rebased onto current main and re-verified the earlier asks against it. The escape is in place: every warn site (the gate notice plus the four resolve-failure warnings) prints the specifier through |
cixzhang
left a comment
There was a problem hiding this comment.
The project-relative resolver fix is useful, but the safe-mode design needs to change at exact head cb5aaef66af3eab487b3a5971da1fe036e30490c. A read-only astryx component command should not execute project theme code behind an opt-out environment variable; the command only needs static custom-variant metadata, and the current resolver does not reliably derive that from normal defineTheme() output anyway. Please split or rework this so trusted astryx theme build emits versioned, schema-validated variant JSON and astryx component reads it without executing project code, falling back to built-in docs when metadata is missing, invalid, or stale. Keep the resolver correctness repair separate if useful. PR 6491 may further settle the general CLI environment-variable policy.
There was a problem hiding this comment.
Thanks — the resolution repair itself looks right: theme packages now resolve from the project's own node_modules, the documented ./src/theme.ts setup loads through the same shared loader configs use, and every warning now prints the configured specifier with control and format characters replaced.
One part needs to change before this can land: the ASTRYX_NO_PROJECT_CODE gate.
- Current CLI policy does not allow a new Astryx-owned environment variable as a behavior control; supported behavior needs a documented command, option, configuration surface, or programmatic API instead.
- The gate also only covers the theme. On the
astryx componentpath, the project configuration and integration manifests load before theme resolution is reached, so someone running the command in an untrusted checkout with the variable set can still execute project code — the switch promises more safety than it delivers.
Please split the gate out of this PR and land the resolution fix on its own. Safe mode for read commands is still worth pursuing separately, ideally in the direction discussed on this PR: a trusted build step emitting static, validated variant data that the component command can read without executing project code at all. One smaller note: the current tests only exercise theme objects with a top-level variants map, while a normal defineTheme() result does not carry one, so the variant benefit for real themes is not yet demonstrated — worth a fixture whichever PR carries the safe-mode rework.
[Automated review]
|
(Posted by Cindy's agent.) Thank you, @bhamodi! This report shaped both the CLI's rules for controls (no environment-variable gates) and the generated theme-module path that shipped in #6874 for installed themes, so the resolution and the gate are covered there. The remaining hardening, sanitizing the configured theme value in warnings, will land separately with credit to you, and the static-metadata safe mode from the review is tracked as follow-up work. Closing this one as superseded. |
…rs (#10764) fix(cli): a theme warning prints as one line without control characters The configured astryx.theme value and the generated theme record come from the checkout. Every theme warning now replaces control and format characters with U+FFFD, so a newline or an escape sequence cannot rewrite the terminal. Carries the warning hardening from #5525. Co-authored-by: Baraa Hamodi <[email protected]>
Summary
resolveTheme()had two problems: itscreateRequirewas bound to the CLI's install location, so package themes resolved from the wrongnode_modules, and it loaded checkout files on every read command with no way to opt out. This keeps every documented setup working exactly as on main, including the theme guide's{"astryx": {"theme": "./src/theme.ts"}}, and puts all theme loading, file and package alike, behind the one safe-mode switch.Changes
importUserModule(the documented.tssetup now uses the same jiti path configs do, instead of relying on Node's type stripping).createRequirebound to the project (<cwd>/package.json), soastryx.themenames packages out of the project's ownnode_modules.ASTRYX_NO_PROJECT_CODE=1: no theme module loads (file, package, orASTRYX_THEME), a one-line notice printed once per process explains why, and rendering degrades theme-less. The variable is read inline so this change stands alone; it is the same switch fix(cli): ASTRYX_NO_PROJECT_CODE=1 keeps the CLI on built-in data #5531'sprojectCodeAllowedreads.printable(), which replaces control and format characters (\p{Cc},\p{Cf}) with U+FFFD, so a checkout-controlled value cannot write escape sequences, newlines, or bidi overrides to the terminal.resolveThemeis now async; its one call site awaits it.Test plan
19 tests in
resolve-theme.test.mjs, each verified to fail when the guard it protects is removed:./src/theme.tswith TypeScript syntax; a child-process test uses anenum(rejected by Node's built-in type stripping) so only the shared jiti loader can pass it.node_modulesresolves (fails against a CLI-bound require).ASTRYX_THEMEstill loads.ASTRYX_THEMEsetups all return null with a probe global proving the module never executed; the notice prints once across repeated reads; any other value of the variable leaves loading on.Also:
clients/clilib + component suites green (181 tests),typecheck:strict, eslint strict,check:changesets,check:cli-structure, and a manual run ofastryx component Buttonagainst a fixture project with a.tstheme, a project-local package theme, andASTRYX_THEME, each with and withoutASTRYX_NO_PROJECT_CODE=1.Notes
projectCodeAllowed().astryx doctorreports the theme field as "wired" from its static presence; under the gate it is configured but not loaded. A follow-up in fix(cli): ASTRYX_NO_PROJECT_CODE=1 keeps the CLI on built-in data #5531 (which already touches doctor) can annotate that state.@astryxdesign/clipatch.