Class SafePathTemplate
polling floor those layers clamp declared poll intervals to.
This is the toolkit's one home for "is this app-declared endpoint safe to fetch from the browser" so the widgets
and views modules can both call it without either depending on the other. The same-origin core
(isSameOriginPath(String)) rejects an absolute URL, a protocol-relative //host prefix, a
scheme (colon-before-slash), and any .. path segment — the base rule every declarative endpoint
shares. isNonTemplatedPath(String) adds the stricter "no {…} placeholder" rule an endpoint that
is not row/parameter-scoped requires (a card field-list, for example, is fixed — it is not fetched
per-row, so a {id} template is meaningless and rejected). A path-templated caller (a calendar that
legitimately needs {year}/{month}) layers isSafeTemplate(String, String...) on top of
isSameOriginPath(String) rather than duplicating the same-origin core. Document links (an event
href) use isSafeDocumentUrl(String), which is the same-origin core plus query/fragment.
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe minimum honored polling interval, in milliseconds. -
Method Summary
Modifier and TypeMethodDescriptionstatic longclampPollInterval(long intervalMs) Clamps a declared poll interval up toMIN_POLL_INTERVAL_MS.static booleanisNonTemplatedPath(String path) Whetherpathis a same-origin path (perisSameOriginPath(String)) that also carries no{…}template placeholder.static booleanisSafeDocumentUrl(String url) Whetherurlis a same-origin document URL (query and fragment allowed).static booleanisSafeTemplate(String template, String... requiredTokens) Whethertemplateis a same-origin path template (perisSameOriginPath(String)) that also contains every required substitution token.static booleanisSameOriginPath(String path) Whetherpathis a same-origin path: not blank, no://, no//prefix, no scheme (colon before the first slash), and no..path segments.
-
Field Details
-
MIN_POLL_INTERVAL_MS
The minimum honored polling interval, in milliseconds.A declared poll interval below this floor is clamped up to it rather than honored as configured — a declarable interval with no floor lets a consumer configure a self-inflicted load problem on a server-side endpoint. This is the single, easily-tested source of truth for the floor shared by every polling widget (view tables, card field-lists, calendars), so a stale/cached client script cannot be tricked into honoring a sub-floor value the server never actually declared.
- See Also:
-
-
Method Details
-
isSameOriginPath
Whetherpathis a same-origin path: not blank, no://, no//prefix, no scheme (colon before the first slash), and no..path segments.The check rejects, and never normalises and then accepts, the characters a browser's URL parser rewrites: a backslash (read as a slash, so
\\hostis protocol-relative), any C0 control character or DEL, and a first or last character at or below U+0020 (stripped, so" //host"resolves cross-host). Internal spaces and non-ASCII characters are still accepted. The JS guards in the console runtimes apply the same rule, andsame-origin-path-corpus.jsonpins them to it.This is the shared same-origin core. It deliberately says nothing about
{…}template placeholders: a per-row/per-parameter caller (which needs{id}) uses this as-is, and a caller that forbids templating layersisNonTemplatedPath(String)on top.- Parameters:
path- The candidate path. Can benull .- Returns:
true if the string is a same-origin path.
-
isNonTemplatedPath
Whetherpathis a same-origin path (perisSameOriginPath(String)) that also carries no{…}template placeholder.A fixed, non-parameterized endpoint (a card field-list refresh, for example) must be exactly the path it declares; a
{id}-style placeholder has no substitution source and is rejected.- Parameters:
path- The candidate path. Can benull .- Returns:
true if the string is a same-origin, non-templated path.
-
clampPollInterval
Clamps a declared poll interval up toMIN_POLL_INTERVAL_MS.- Parameters:
intervalMs- The declared interval, in milliseconds.- Returns:
max(intervalMs,MIN_POLL_INTERVAL_MS).
-
isSafeTemplate
Whethertemplateis a same-origin path template (perisSameOriginPath(String)) that also contains every required substitution token.A per-month calendar GET like
/events/{year}/{month}is same-origin and must actually declare the tokens the emitter will substitute. Built onisSameOriginPath(String)rather than a second same-origin implementation.- Parameters:
template- The candidate template. Can benull .requiredTokens- The literal tokens (for example"{year}","{month}") that must all be present. May be empty (same-origin only).- Returns:
true iftemplateis same-origin and contains every token.
-
isSafeDocumentUrl
Whetherurlis a same-origin document URL (query and fragment allowed).Mirrors the client-side
isSafeDetailUrlcheck. Query/hash never trip the absolute/scheme/..rejections inisSameOriginPath(String); a?value containing://is still rejected.- Parameters:
url- The candidate document URL. Can benull .- Returns:
true if the URL is a safe same-origin document link.
-