Class SafePathTemplate

java.lang.Object
org.apache.juneau.commons.http.SafePathTemplate

public final class SafePathTemplate extends Object
Shared, dependency-free predicates for validating same-origin request paths declared by higher layers, plus the single 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 Details

    • MIN_POLL_INTERVAL_MS

      public static final long 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

      public static boolean isSameOriginPath(String path)
      Whether path is 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 \\host is 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, and same-origin-path-corpus.json pins 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 layers isNonTemplatedPath(String) on top.

      Parameters:
      path - The candidate path. Can be null.
      Returns:
      true if the string is a same-origin path.
    • isNonTemplatedPath

      public static boolean isNonTemplatedPath(String path)
      Whether path is a same-origin path (per isSameOriginPath(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 be null.
      Returns:
      true if the string is a same-origin, non-templated path.
    • clampPollInterval

      public static long clampPollInterval(long intervalMs)
      Clamps a declared poll interval up to MIN_POLL_INTERVAL_MS.
      Parameters:
      intervalMs - The declared interval, in milliseconds.
      Returns:
      max(intervalMs, MIN_POLL_INTERVAL_MS).
    • isSafeTemplate

      public static boolean isSafeTemplate(String template, String... requiredTokens)
      Whether template is a same-origin path template (per isSameOriginPath(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 on isSameOriginPath(String) rather than a second same-origin implementation.

      Parameters:
      template - The candidate template. Can be null.
      requiredTokens - The literal tokens (for example "{year}", "{month}") that must all be present. May be empty (same-origin only).
      Returns:
      true if template is same-origin and contains every token.
    • isSafeDocumentUrl

      public static boolean isSafeDocumentUrl(String url)
      Whether url is a same-origin document URL (query and fragment allowed).

      Mirrors the client-side isSafeDetailUrl check. Query/hash never trip the absolute/scheme/.. rejections in isSameOriginPath(String); a ? value containing :// is still rejected.

      Parameters:
      url - The candidate document URL. Can be null.
      Returns:
      true if the URL is a safe same-origin document link.