11. How would you preserve authorization and analytics-event integrity in an infinite product-listing frontend?
An infinite product-listing frontend records impressions and clicks while pages load asynchronously. Define which events the browser may propose and which facts the server must verify, how item and page identities prevent replay or attribution to the wrong query, how consent and privacy affect analytics payloads, and how offline queues, retries, duplicate events, tampered clients, and logout are handled.
I would treat every browser analytics event as an untrusted proposal. The server would verify authorization, query-page-item relationships, consent, freshness, and duplicate status. Stable event IDs make retries idempotent, while bounded offline queues and logout-aware identity scoping prevent stale, replayed, or misattributed events.
The main idea is that the web page can report what it believes happened, but it cannot prove that the report is true. The system should check that the person was allowed to receive the product, that the product really belonged to the list and page being shown, and that the same report is not counted twice. It should also collect only necessary information and respect the person's privacy choices. If the device loses its connection, retries later, sends duplicate reports, is modified by the user, or another person signs in, old activity must not be incorrectly counted or assigned.
- Are impressions and clicks used only for analytics, or can they affect billing, ranking, recommendations, experiments, or fraud decisions?
- Can different users receive different products because of authorization or account state?
- Must analytics survive offline periods and page reloads, or is best-effort delivery acceptable?
- Which consent categories control analytics collection, and what must happen to already queued events when consent is withdrawn?
- How long should query and page identities remain valid for delayed or offline events?
I would start with the trust boundary: JavaScript running in the browser is not trusted. A user can modify the application, alter network requests, call the analytics endpoint directly, replay captured requests, change product IDs, invent timestamps, or automate events. The browser may therefore propose that an impression or click happened, but it cannot be authoritative evidence that pixels were genuinely visible or that a human genuinely clicked them.
Authentication answers, "Who is making this request?" Authorization answers, "Is this identity allowed to access this product or operation?" The trusted server must enforce authorization. A valid login does not prove that every product ID supplied by the browser is authorized for that user.
When the server returns a listing, I would give that response an opaque server-issued query identity and page identity. The server keeps or can reconstruct the relationship among the authenticated or anonymous session, normalized listing context, page, authorized result set, and expiration time. The identities should be unpredictable or integrity-protected so a client cannot successfully manufacture another valid listing context merely by editing fields.
The browser can propose observations such as event type, a stable event ID, query ID, page ID, item ID, client-observed time, visible position, and limited presentation information. These are claims, not trusted facts. In particular, a client timestamp is not proof of when an event really occurred, a position is not proof that the item was visible, and an impression event is not proof that a human actually saw the item.
The server should verify the facts it can know. It validates the event schema and permitted event type, checks that the query and page identities are valid and unexpired, confirms that the page belongs to the expected query context, confirms that the item belongs to that page or authorized result set, and applies the required product authorization rules. If the analytics endpoint is associated with an authenticated session, the supplied listing context must also match the appropriate identity or session scope.
That binding prevents simple attribution attacks. If an attacker changes an item ID to another product, the server can reject it because that item was not part of the referenced page or authorized result set. If the attacker combines a page ID with an unrelated query ID, the server rejects the mismatched relationship. The system should not trust raw browser-provided query text as proof of which search produced an event.
I would be explicit about the remaining limitation: server validation can prove that an event refers to a legitimate listing context and an authorized item, but it cannot make an untrusted browser a trustworthy sensor. A malicious client may still generate plausible impressions or clicks for items it legitimately received. If these events affect money, ranking, fraud decisions, or another sensitive system, I would add server-side abuse controls such as rate limits, anomaly detection, aggregate consistency checks, and downstream trust weighting. Those controls reduce abuse but still should not be described as proof of human behavior.
For retries, every logical event should keep the same unique event ID. The ingestion service should be idempotent, meaning that processing the same logical event more than once produces one accepted result rather than multiple counts. The server keeps enough deduplication state for the required retry window and ignores or returns success for an already accepted event without counting it again.
An attacker can create many new event IDs, so deduplication alone is not an anti-fraud mechanism. It solves accidental duplicates caused by retries, reconnects, or repeated delivery. Abuse involving many distinct events needs separate server-side rate, anomaly, or business-rule controls.
If offline support is required, I would use a bounded queue. Each queued entry contains only the minimum analytics data required for later delivery and retains its original event ID and server-issued listing context. Retries use backoff and reuse that event ID rather than creating a new logical event. The queue has limits on age and size so old or excessive data does not remain indefinitely. The server still performs freshness and context validation when delayed events eventually arrive.
Logout is an identity boundary. When logout starts, the frontend should stop producing authenticated analytics events and clear or segregate queued records associated with that identity. A later user must never inherit those events. If policy explicitly permits pre-logout events to be delivered afterward, they retain their original identity and listing context and are validated against that original context; they must never be relabeled as belonging to the newly authenticated user.
Consent is also important. The frontend should stop creating analytics that the current consent state does not allow. If consent is withdrawn, queued events that are no longer permitted should be deleted or suppressed according to the application's privacy policy. Server-side analytics processing should also enforce applicable consent rules when the required consent state is available there. Analytics payloads should contain only necessary data and should avoid unnecessary personal information.
I would never put server secrets, private signing keys, long-lived credentials, or other authoritative secrets in frontend JavaScript. Anything shipped to the browser must be considered observable by the user. If the server uses integrity-protected listing tokens, creation or signing must happen on the trusted server.
Browser storage also needs care. localStorage and IndexedDB are readable by JavaScript running in the application's origin, so an XSS vulnerability can expose queued analytics stored there. I would keep the queue minimal, avoid secrets and unnecessary sensitive information, limit retention, and clear identity-scoped records when appropriate.
If authentication uses cookies, sensitive session cookies should normally use Secure, HttpOnly, and an appropriate SameSite setting. HttpOnly prevents normal page JavaScript from reading the cookie, Secure restricts transmission to HTTPS, and SameSite helps reduce some cross-site request risks.
If a cookie-authenticated analytics endpoint performs security-sensitive or state-changing processing, I would also assess CSRF. SameSite cookies, CSRF tokens where appropriate, and checks such as Origin or Fetch Metadata can help. CORS is not authorization. CORS controls which browser origins can read certain cross-origin responses; it does not stop an attacker from sending arbitrary requests with a custom client. The same-origin policy is also a browser restriction, not proof that requests reaching the server came from trusted application code.
XSS matters because injected JavaScript executes inside the page's security context and can fabricate analytics or read browser-accessible data. Product names and other untrusted strings should be rendered with textContent, safe DOM APIs, or normal framework escaping. I would not use innerHTML with untrusted content. If intentionally allowing HTML, I would sanitize it with a well-maintained sanitizer appropriate for that context. A restrictive Content Security Policy and Trusted Types can provide additional defense against injection mistakes where the application architecture supports them.
Third-party scripts and dependencies increase the attack surface because code running in the page may observe application data and generate requests. I would minimize third-party analytics and tag scripts, give them only the data they need, restrict script sources with Content Security Policy where practical, review dependency changes, lock dependency versions appropriately, keep dependencies patched, and avoid exposing authentication material or sensitive analytics data to unnecessary third-party code.
Safe failure means malformed, expired, context-mismatched, unauthorized, disallowed, or duplicated events do not become accepted analytics records. Error responses should not reveal sensitive authorization details. Security logging should capture useful information such as rejection categories and opaque correlation IDs without recording credentials, session secrets, private signing material, or unnecessary personal data.
I would verify the design with adversarial tests: change an item ID, combine a page with the wrong query, use an expired page identity, replay the same event ID, retry after timeouts, create many different event IDs, send delayed offline records, withdraw consent before delivery, log out and sign in as another user, request an unauthorized product, modify timestamps and positions, and call the endpoint without using the normal frontend. I would also monitor duplicate, rejection, expiration, and abuse signals. The goal is that modifying browser code cannot turn client-supplied claims into trusted authorization or trusted server facts.
- Define the browser as an untrusted event proposer and the server as the authorization and acceptance authority.
- For each listing response, create opaque or integrity-protected server-issued query and page identities tied to the real listing context, authorized result set, session or identity scope, and expiration.
- Let the browser submit only minimal observations plus those server-issued identities and one stable event ID per logical event.
- Validate schema, event type, identity scope, query-page relationship, item membership, authorization, consent, and freshness on the server.
- Accept that genuine human visibility or clicking cannot be proven solely from an untrusted browser; add rate, anomaly, or business-rule controls when analytics has sensitive downstream effects.
- Deduplicate accepted event IDs so normal retries are idempotent.
- Keep offline queues bounded, privacy-minimized, short-lived, and associated with their original identity and consent context.
- On logout or consent withdrawal, stop new disallowed events and clear or segregate queued events that must no longer be delivered.
- Reject invalid events safely, log non-sensitive reasons, and test tampering, replay, retries, offline delivery, consent changes, and identity transitions.
Creating one event in the browser is normally constant work. A client offline queue uses storage proportional to the number and size of pending events, so it should have strict size and age limits. Server processing needs a small set of validations or lookups for listing context, item membership, authorization, expiration, consent, and duplicate detection. Deduplication needs temporary state proportional to the number of event IDs retained during the retry window. At high analytics volume, storage, lookup traffic, abuse detection, and retention become the main operational costs. Strong validation adds server work, but it prevents attacker-controlled browser claims from being treated as trusted authorization or attribution facts. Maintenance cost comes from keeping event schemas, authorization rules, listing-context formats, expiration policies, consent handling, and deduplication behavior consistent.
This tests whether the candidate understands the browser-server trust boundary, the difference between authentication and authorization, what analytics facts a client can only claim versus what a server can verify, replay and attribution threats, privacy-aware analytics, asynchronous frontend behavior, retry and deduplication design, and safe handling of tampered clients, offline queues, consent changes, and logout.
Common mistakes include trusting browser fields such as authorized=true; treating authentication as item-level authorization; accepting arbitrary item IDs without verifying their relationship to the referenced query and page; trusting raw query text, client timestamps, viewport positions, or impression claims as authoritative facts; claiming that a server can prove a human actually saw or clicked something from an untrusted browser alone; using deduplication as if it prevents an attacker from creating many new event IDs; generating a new event ID on every retry and double-counting events; allowing listing identities to remain valid indefinitely; replaying one user's offline queue after another user logs in; continuing disallowed analytics after consent withdrawal; storing secrets, long-lived credentials, or unnecessary sensitive data in analytics payloads or browser storage; assuming CORS is authorization; ignoring CSRF when cookie-authenticated state-changing endpoints require protection; using innerHTML with untrusted product data; giving third-party scripts unnecessary access to sensitive information; relying only on client-side validation; logging secrets in rejection diagnostics; and treating input filtering alone as a complete security control.
Lead with: "The browser proposes events; the server verifies the facts it can actually know." Then explain query-page-item binding, server-side authorization, the limitation that human visibility cannot be proven from an untrusted client, idempotent retries, privacy and consent, offline queues, logout, and concrete tampering tests.









