Repository navigation
fix(net)!: one strict path rule, minted and parsed #7037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
54c3664
2a025be
a43b50e
07cf926
2d3581d
4cd5254
a44aae1
3095be4
28fbd83
b51e77d
619fe84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,25 @@ | ||
| import { Epoch, Path } from "@moq/net"; | ||
| import * as z from "@zod/mini"; | ||
|
|
||
| function isRelative(text: string): boolean { | ||
| try { | ||
| Path.normalizeRelative(text); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reject references longer than 4096 UTF-8 bytes.
|
||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Zod schema for a relative broadcast reference stored in a catalog (a rendition's | ||
| * `broadcast` field, e.g. "./source"). Normalizes the input the same way the Rust | ||
| * `path::Relative` type does so JS and Rust agree byte-for-byte after deserialization. | ||
| * `broadcast` field, e.g. "./source"). Refuses and normalizes the input the same way the Rust | ||
| * `path::Relative` type does so JS and Rust agree byte-for-byte after deserialization: a | ||
| * leading, trailing, or doubled `/` or a lone `\` refuses the catalog. | ||
| * Resolve it against the catalog broadcast's own path with `Path.tryResolve`, which returns | ||
| * `undefined` for a reference that walks above the root: hang requires rejecting such a catalog. | ||
| */ | ||
| export const RelativeBroadcastSchema: z.ZodMiniType<RelativeBroadcast, string> = z.pipe( | ||
| z.string(), | ||
| z.string().check(z.refine(isRelative, "expected a relative broadcast path")), | ||
| z.transform(Path.normalizeRelative), | ||
| ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -406,7 +406,14 @@ export class AnnounceHistory { | |
| const head = Path.parts(this.#base(msg.pathBase).suffix); | ||
| const keep = msg.pathBase.keep; | ||
| if (keep > head.length) throw new ProtocolViolation(`announce keeps ${keep} of ${head.length} segments`); | ||
| suffix = Path.join(Path.from(...head.slice(0, keep)), suffix); | ||
| // Joined as text before parsing: a kept segment may end in the `\` of an escaped `/`. | ||
| const kept = head.slice(0, keep); | ||
| if (suffix !== Path.empty()) kept.push(suffix); | ||
| try { | ||
| suffix = Path.from(kept.join("/")); | ||
| } catch (cause) { | ||
| throw new ProtocolViolation("announce keeps half an escape", { cause }); | ||
| } | ||
|
Comment on lines
+409
to
+416
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| const error = Path.check(suffix); | ||
| if (error) throw new ProtocolViolation(error); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reject roots beyond the wire's 32-part limit.
If a root has 33 parts,
validateaccepts it, but@moq/netrejects that path on wire decode.Key.signcan therefore mint a grant for a root that a peer cannot use. Add the part-count check here and inrs/moq-auth/src/path.rs:18-34. Test the 32-part and 33-part boundaries in both languages. (raw.githubusercontent.com)As per coding guidelines, “Fail loud and early. Error on unsupported or malformed input rather than warn and continue: supported or refused.”
Source: Coding guidelines