Repository navigation
fix: only allow strings in as and is props - #587
Conversation
Vue mounts an array as a component and React throws on a non-string element type, so markdown-authored `as` / `is` values must be strings. `tag` keeps the object-only check, since it is often a data prop. Amp-Thread-ID: https://ampcode.com/threads/T-01a1cf50-cedc-7518-a92e-83006b718b89
Architecture Data flow Review 1 finding · reviewed
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Documentation previews📚 Preview all documentation changes (follows new pushes) Pinned to the current head: |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
comark
@comark/angular
@comark/ansi
@comark/html
@comark/nuxt
@comark/react
@comark/svelte
@comark/vue
commit: |
Merging this PR will not alter performance1 warning
Comparing |
as and is propsas and is props
Follow-up to #579. The renderers dropped markdown-authored
as,isandtagvalues that were objects or functions, but let arrays, numbers and booleans through on the assumption thath()renders nothing for them. That only holds for Vue, and only by luck. Vue treats an array as a stateful component, sinceisObject([])is true. React throws "Element type is invalid" when a component renders a non-stringas, which can take the whole page down unless an error boundary catches it. Components that render whateverasthey receive, such as Reka UI'sPrimitive, pass the value straight on.What changed
asandis, plus their bindings, now accept only a string,nullorundefinedwhen the value comes from markdown or is resolved from bound data. Anything else is dropped and the component falls back to its default tag. This applies with or without thesecurityplugin, because the same check (isComponentSelectorViolationininternal/sanitize.ts) runs at parse time and at render time.tagis unchanged and still drops only objects and functions. It is often a data prop (tag: [vue, nuxt]), and no renderer resolves it as a component name.transformNodeare not checked, as before.Evidence
The new tests fail on
mainand pass on this branch:mainsecurity.test.ts: strips an array, number or boolean as or isbound-component-props.test.ts: does not hand a non-stringasoristo a component<!---->(array mounted as a component) instead of<div>poly</div>bound-component-props.test.tsx: does not hand a non-string as to a componentError: Element type is invalid: expected a string … but got: object.One existing test, "keeps an array, number or boolean as or is or tag", now asserts the opposite for
asandis. It is replaced with one that keeps a string ornullas/isand an array or numbertag.pnpm test,pnpm test:sanitizer(437 passed),pnpm typecheckandpnpm lintpass locally.ELI5
astells Comark which element to draw, like "section" or "button". That name should always be text. Before this change, other kinds of values could slip through and confuse Vue or crash React. Now anything that isn't text is ignored.Summary by CodeRabbit
asoris, including arrays and values from frontmatter, are discarded so polymorphic components use their default element.tagremain available as data, while object-valuedtagprops are discarded. String values fortagcontinue to select the requested tag.as,is, andtagvalues are handled, including values supplied through frontmatter.