Bronnen · 63

HTTP-caching: bescherm gepersonaliseerde antwoorden

Scheid gedeelde, privé- en applicatiecaches, inspecteer sleutels, hervalidatie en ongeldigverklaring na wijzigingen in toegangsrechten.

Bijgewerkt · 6 min

Lege beveiligde gang met servers en netwerken Redactionele illustratie gegenereerd met AI

Wat deze handleiding helpt bereiken

  • Inventarisatielagen
  • Retentie kiezen
  • Sleutels inspecteren
  • Hervalidatie en wijziging uitvoeren

Snelle controle

  • Betekent geen cache dat er niets wordt bewaard?
  • Beschermt Vary toegangsrechten?
  • Moet elke API in de cache worden opgeslagen?

Stapsgewijze methode

  1. 1

    Inventarisatielagen

    Lijst browser-, CDN-, proxy-, service worker- en applicatiecaches. Classificeer openbare en gepersonaliseerde reacties. Een HTTP-beleid beschrijft niet automatisch de caching die in de code is geïmplementeerd.

    Resultaat: diagram van lagen en eigenaren.

  2. 2

    Retentie kiezen

    RFC 9111 onderscheidt richtlijnen: 'no-cache' vereist validatie vóór hergebruik, 'no-store' verbiedt de relevante HTTP-opslag en 'unqualified private' sluit gedeelde opslag uit. Geen enkele op zich garandeert systeemvertrouwelijkheid.

    Resultaat: bewaarbeleid per reactie.

  3. 3

    Sleutels inspecteren

    Controleer de methode, URI en dimensies die een weergave wijzigen. Variatie betreft aanvraagvelden; het betreft geen autorisatie. Zoek naar weggelaten taal, formaatonderhandeling en accountcontext in applicatielagen.

    Resultaat: sleutels en scheidingstests.

  4. 4

    Hervalidatie en wijziging uitvoeren

    Test nieuwe en verouderde reacties, gegevensupdates en ingetrokken rechten. Inspecteer ETag, voorwaardelijke validatie en gedrag bij onbeschikbare oorsprong. Een voorheen correcte reactie kan gevoelig worden na intrekking.

    Resultaat: traceringen voor en na.

  5. 5

    Herhaling met twee accounts

    Gebruik fictieve identiteiten en markers. Wissel verzoeken af ​​naar dezelfde URI met warme en koude caches. Controleer uitloggen, directe links en logging zonder echte tokens vast te leggen.

    Resultaat: negatieve tests en invalidatiestrategie.

Meet ook hoe actueel cachegegevens zijn

Fictief voorbeeld: deze gegevens beschrijven geen klant of waargenomen resultaat.

Situatie

Twee leesacties zijn snel, maar één toont na een bronwijziging nog de oude beschikbaarheid.

Controleren

Vergelijk waarde, versie, leeslocatie en tijd sinds wijziging. Test ongeldig maken, verlopen en toegang tot de bron volgens de systeemafspraken.

Handelen

Bepaal aanvaardbare veroudering per toepassing en bewaak verschillen. Lagere vertraging bewijst geen consistentie van geleverde gegevens.

Herbruikbaar werkblad

Vul in met uw geautoriseerde observaties. Deze velden zijn een werksjabloon, geen waargenomen resultaten.

VeldInformatie om vast te leggen
ReactieOpenbaar of gepersonaliseerd; dimensies
LaagCache, eigenaar en sleutel
BeleidBewaring, actualiteit en validatie
ProefFictief account, wijziging en observatie

Fictief uitgewerkt voorbeeld

Illustratieve situatie

Fictief voorbeeld: een CDN hergebruikt een profielreactie op dezelfde URI voor twee testaccounts.

Beslissing en verwachte bewijs

Het scenario detecteert lekken, onderzoekt beleid en sleutels en speelt vervolgens opnieuw af na correctie en intrekking van toegang.

Onderscheid de mechanismen

MechanismeDoelVerificatie of beperking
geen cacheOpslag toestaan ​​met vereiste validatieNiet interpreteren als geen opslag
Niet-gekwalificeerd privéGedeelde caching uitsluitenNiet interpreteren als een vertrouwelijkheidsgarantie
geen opslagVoorkom de relevante HTTP-opslagControleer applicatiecaches en geschiedenis afzonderlijk

Managementindicatoren

IndicatorWat het meetEerste actie
AccountscheidingGeen markering van een ander accountInspecteer body, links en metadata
Leeftijd en validatieHergebruik in overeenstemming met beleidTest vervaldatum en niet-beschikbare oorsprong
OngeldigmakingsvertragingTijd tot gecorrigeerde weergaveBenoem elke laag die nog steeds verouderd is

Veelvoorkomende fouten

  • Niet interpreteren als geen opslag
  • Niet interpreteren als een vertrouwelijkheidsgarantie
  • Controleer applicatiecaches en geschiedenis afzonderlijk

Veelgestelde vragen

Betekent geen cache dat er niets wordt bewaard?

Nee. Het vereist validatie vóór hergebruik; het verbiedt opslag niet zoals 'geen opslag' dat wel doet.

Beschermt Vary toegangsrechten?

Nee. Het neemt deel aan de selectie van de weergave; Autorisatie blijft gescheiden.

Moet elke API in de cache worden opgeslagen?

Nee. Voordelen hangen af ​​van kosten, actualiteit en risico. Gevoelige reacties kunnen het vermijden van gedeelde caches rechtvaardigen.

ETag, HTTP-cache en gelijktijdige wijzigingen

De uitgebreide toelichtingen zijn in deze editie beschikbaar in het Engels.

ETag: revalidate responses and prevent lost updates

An ETag is an opaque validator for the selected representation. It compares versions; it is neither authorisation nor an access token, and it need not be a file hash. Personalised responses require separate decisions about access, cache selection and HTTP conditions.

Local teaching model: a representation already exists; at most one conditional field contains a single ETag or *. GET, HEAD and PUT are covered. Tag lists, date validators, ranges, creation, combined conditions and the already-succeeded modification exception are excluded. No network call, storage or state change occurs; this does not test your API.

Fictief leeg netwerklaboratorium met apparatuur op een donkere, amberkleurig verlichte werkbank. Redactionele illustratie gegenereerd met AI
Generated conceptual scene: a fictional empty network laboratory. It shows neither a real facility nor a protocol measurement.

Strong and weak ETag comparison serve different purposes

If-Match requires strong comparison: neither tag may start with W/. If-None-Match uses weak comparison, matching the opaque values regardless of W/. Values remain case-sensitive. The * wildcard checks representation existence here, not a particular version.

Strong and weak ETag comparison serve different purposes
Current tagReceived tagStrong comparisonWeak comparison
"v1""v1"MatchesMatches
"v1"W/"v1"Does not matchMatches
W/"v1"W/"v1"Does not matchMatches
"v1""v2"Does not matchDoes not match
"v1""V1"Does not matchDoes not match

Simulate an HTTP decision without contacting a server

The six parameters yield 432 combinations. Requiring a conditional field and selecting 204 for successful PUT are policies of this fictional scenario. Requiring any condition does not prevent every lost update: If-Match: * compares no version.

Model decision : 304

304: If-None-Match finds a weak match for GET or HEAD. Reuse the stored representation under cache rules with the revalidation metadata.

304 and 204: no response content.

Request excerpt

GET /demo/resource HTTP/1.1
Host: api.example.test
If-None-Match: W/"v1"

Response excerpt

HTTP/1.1 304 Not Modified
Date: Thu, 22 Oct 2026 00:00:00 GMT
ETag: "v1"
Cache-Control: private, no-cache

Fictional HTTP/1.1 excerpts for reading: bodies are omitted even where allowed. api.example.test is an example domain. The date is fixed. This model does not update the ETag after PUT; the separate walkthrough follows successive versions.

Ten reproducible situations

Ten reproducible situations
Fictional situationCondition and expected outcomeInterpretation
Read using a weak tagGET · "v1"
If-None-Match: W/"v1" → 304

Access allowed · Conditional field optional

W/"v1" and "v1" match weakly.
Different client versionGET · "v1"
If-None-Match: "v2" → 200

Access allowed · Conditional field optional

The client needs the selected representation.
HEAD revalidationHEAD · "v1"
If-None-Match: "v1" → 304

Access allowed · Conditional field optional

The status can be 304; the response has no content.
Write based on an old versionPUT · "v2"
If-Match: "v1" → 412

Access allowed · Conditional field optional

Read again and resolve the conflict before retrying.
Weak tag with If-MatchPUT · "v1"
If-Match: W/"v1" → 412

Access allowed · Conditional field optional

Strong comparison rejects a weak tag.
Required condition absent on PUTPUT · "v1"
none → 428

Access allowed · Conditional field required

428 follows the policy announced by this API.
Access denied despite matching tagGET · "v1"
If-None-Match: "v1" → 403

Access denied · Conditional field optional

Authorisation precedes HTTP conditions.
Write on the correct versionPUT · "v1"
If-Match: "v1" → 204

Access allowed · Conditional field required

The model accepts PUT and selects a 204 success.
If-None-Match: * on existing dataPUT · "v1"
If-None-Match: * → 412

Access allowed · Conditional field optional

The wildcard matches any existing representation.
If-Match: * on existing dataPUT · W/"v1"
If-Match: * → 204

Access allowed · Conditional field required

The wildcard passes even with a weak current tag: it does not protect a version.

Four rules for a personalised response

Four rules for a personalised response
Response fieldHTTP effect within this scopeEvidence to retain
Cache-Control: no-cacheUnqualified no-cache permits storage, but any reuse needs successful validation with the origin server.Observe a conditional round trip; do not read no-cache as a storage prohibition.
Cache-Control: no-storeForbids storage by private and shared HTTP caches. It is not a general privacy guarantee.Also review logs, history, screenshots and application storage.
Cache-Control: privateUnqualified private forbids storage by a shared cache; a private cache may store under the other constraints.Distinguish browser, proxy and CDN. A directive does not replace access checks.
VaryAdds the named request fields to selection of a stored response. It does not decide who may access a resource.Test relevant variants. Do not assume a cookie or Authorization automatically prevents all caching.

Useful API acceptance evidence

  • Expected request and status: method, test resource, access rights, conditional field and current ETag. Use fictional data and remove secrets.
  • Observed response: status, ETag, Date, Cache-Control, Vary and no content for HEAD, 204 or 304. A 304 must carry the required metadata that would have accompanied the 200.
  • Concurrency: verify that a stale write fails without changing the resource; retain the conflict-resolution decision. Do not blindly replace the ETag and resend the same write.

Follow the two-client conflict →

Primary references and limits

The standards define HTTP conditions and caching. The ten cases, laboratory and two-client walkthrough are original illustrations. Displayed results are calculated by this local model, not measurements of this site or your infrastructure.

References reviewed

Officiële referenties

Referenties ondersteunen de methode. Pas controles aan uw context aan; ze zijn geen certificering. Originele referentietitels en brondocumenten kunnen in een andere taal zijn.

Bronnen geraadpleegd op .