skip to content

In a SAML metadata document, what do `validUntil` and `cacheDuration` each tell the party consuming it?

level: middleimportance: must knowfreq 50%

answer

  1. one is absolute, one is relative
  2. expiry versus refresh interval
  3. root element needs at least one
  4. cacheDuration floors how fast change lands
  5. past validUntil means stop, not degrade

basics

~20 s

validUntil is an absolute instant after which the element and its contents must not be used at all. cacheDuration is a relative ceiling on how long a consumer may keep a copy before refetching. They answer different questions and a root element needs at least one.

solid answer

~50 s

`validUntil` is an expiry: an absolute UTC instant, and after it passes the element carrying it — and everything under it — must no longer be used. `cacheDuration` is a caching ceiling: a relative duration saying how long a consumer may hold a copy before it should fetch again. One is *when this stops being true*, the other is *how stale your copy may get*. A root element is required to carry at least one of the two, and carrying both is normal: a consumer then refreshes on the `cacheDuration` rhythm and hard-stops at `validUntil`. The practical consequence is asymmetric. A long `cacheDuration` is cheap until you need to change a key quickly, because it is the floor on how fast any change can reach a counterparty. A `validUntil` that passes does not degrade anything gradually — every relationship relying on that document stops at the same instant.

code

xml · 13 lines
xml
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
                     entityID="https://idp.operator.example/saml"
                     validUntil="2027-03-01T00:00:00Z"
                     cacheDuration="P7D">
  <!-- consumer refreshes at least weekly (cacheDuration),
       and must stop using this content entirely after validUntil -->
  <md:IDPSSODescriptor
      protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
    <md:SingleSignOnService
        Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
        Location="https://idp.operator.example/saml/sso"/>
  </md:IDPSSODescriptor>
</md:EntityDescriptor>

go deeper

for a junior

Remember that one of the two is a date after which the document is unusable and the other is how long a copy may be kept before fetching again. Know that a document should carry at least one.

for a middle

Explain the mechanics: an absolute instant bounding the element and its children, a relative duration bounding staleness, and a consumer refreshing at the earlier horizon of the two.

for a senior

Show that these attributes set the change clock for the whole relationship — a week of caching is a week of notice you cannot buy back — and that an unrenewed expiry is an outage with a date on it.

for a principal

Treat the caching ceiling as a standing policy decision across the estate: what emergency response time are you buying, what load and availability dependency are you creating at the publication location, and who renews the deadlines.

## Two attributes, two different questions A SAML metadata document is consumed as a cached copy. Both freshness attributes exist because the party reading the document is not the party maintaining it, and the reader has to decide on its own when its copy is too old to act on. | attribute | kind of value | question it answers | what it does **not** say | |---|---|---|---| | `validUntil` | an absolute instant, UTC | after when must this content not be used at all? | nothing about how often to refetch | | `cacheDuration` | a relative duration, e.g. `P7D`, `PT12H` | how long may a copy be held before refetching? | nothing about whether the content is still valid | They are independent, and a document commonly carries both. The root element of a metadata instance is required to carry at least one of them — a document with neither leaves the consumer with no stated basis for ever giving up its copy. ## `validUntil` is a hard stop, not a hint `validUntil` appears on the element it bounds, and it bounds that element **and its descendants**. Because it sits inside the document, the maintainer controls it and the consumer cannot extend it. Once the instant passes, the correct behaviour is to stop using the content, not to fall back to the last copy that parsed. That is severe on purpose, and it has a consequence people meet only once: - The keys a counterparty believes live in this document. - Expiry is **simultaneous** for everyone holding that copy. - So a `validUntil` that quietly passes does not slow anything down or degrade one login — it stops every login with that counterparty at the same moment, with nothing in the message exchange looking wrong. A useful habit is to treat `validUntil` as an operational deadline you renew on a schedule, not a security control you tighten. Setting it a month out and forgetting is a self-inflicted outage with a date on it. ## `cacheDuration` is a ceiling on staleness `cacheDuration` is written as an XML Schema duration — `PT12H`, `P1D`, `P7D` — and tells a consumer the maximum period it may go on using a copy before fetching again. Two things follow: 1. It is an upper bound, not a schedule. A consumer may refetch more often; it should not go longer. 2. It says nothing about validity. A copy whose `cacheDuration` has elapsed is not *invalid*, it is *due for refresh* — the content is still bounded by `validUntil`. ## Why the pair decides how fast you can move The reason this leaf matters in an interview is that these two attributes, and nothing else in the document, set the clock on every change the pair will ever make. Consider a regulator's reporting portal and several hundred licensed operators. The portal publishes `cacheDuration="P7D"`. It now needs to change the public key its counterparties hold: - Publishing the change is instantaneous. - **Arrival** is not. A counterparty that fetched yesterday is entitled to go on using yesterday's copy for the rest of the week. - So the earliest moment at which every counterparty can be assumed to hold the new content is a week away, no matter how urgent the reason. The trade-off runs both ways: - **Long `cacheDuration`** (days): few fetches, tolerant of an outage at the publication location, and a change that needs days to land. - **Short `cacheDuration`** (an hour): changes land fast, but every counterparty refetches constantly and your publication location becomes a dependency of their logins. - **`validUntil` far out**: fewer renewals, and a longer window in which nobody notices the document is unattended. - **`validUntil` near**: forces the relationship to be maintained, at the cost of an outage the day maintenance slips. ## The common misreadings - Treating `cacheDuration` as an expiry, and so believing a copy "went invalid" after twelve hours when the document was good for a year. - Treating `validUntil` as advisory and continuing on the last good copy — the one behaviour the attribute exists to forbid. - Reading either attribute as a statement about the embedded certificate's own lifetime. They bound the **document's** usability; a certificate's own dates are a separate matter, and the two routinely disagree. - Assuming a shortened `cacheDuration` binds immediately. It binds the copies fetched *after* it was published, which is why freshness policy always takes effect one generation late.

  • A document carries both attributes and they disagree — `cacheDuration` is `P7D` but `validUntil` is two days away. What should a consumer do?
    Both apply; neither overrides the other. The copy may be held for up to seven days by the caching rule, but it must not be used at all after `validUntil`, which arrives first. In practice a consumer refreshes at the earlier of the two horizons, so it refetches before the hard stop rather than at it.
  • Why is a document with neither attribute on its root element a problem?
    Because nothing tells the consumer when to let go. The copy can be kept indefinitely and a key change may never reach it, while the maintainer has no way to signal that the content has been superseded. That is why the root element of a metadata instance is required to carry at least one of them.
  • Does `validUntil` expiring mean the counterparty's key has been compromised?
    No. It means the document has passed the date its maintainer set and must not be used. The usual cause is an unrenewed document, not an incident. The point of the attribute is that a consumer stops rather than guessing which of those two it is.

saying these in an interview costs you the question

  • Calls cacheDuration the document's expiry date
  • Keeps using the last good copy after validUntil passes
  • Thinks validUntil describes the embedded certificate's lifetime
  • Assumes a shortened cacheDuration binds copies already held
  • Says a stale document degrades logins gradually rather than all at once