Skip to content

    Frontend System Design

    Threat Modeling for Front Ends: Trust Boundaries in the Browser

    Threat model a front end: map what the browser trusts, apply STRIDE to an orders dashboard, rank the threats and pick defenses from XSS to third-party scripts.

    By Published 13 min read

    • frontend-system-design
    • threat-modeling
    • browser-security
    • stride
    Share

    Standard lessonadvancedFrontend System Design

    Before this: Content Security Policy, Dependency and Supply-Chain Security

    What you'll learn: By the end of this lesson you will be able to draw the trust boundaries of a browser application, name what an attacker wants from a front end, apply STRIDE to each data flow that crosses a boundary, rank the threats and match each to a defense from the earlier security lessons, and decide when a new feature (a chat widget, a payment frame) means the model must be redone.

    A market stall is not a bank branch. In a branch you own the walls, the locks and the cameras. At a stall in a foreign market you own a table and a sign; the crowd, the neighbours' stalls and the weather are not yours. A front end is the stall. Your code runs on the user's machine, next to other sites, browser extensions and scripts you included from vendors, and the person at the keyboard can open the developer tools and change anything they like.

    So front-end security starts with a map, not a checklist. The XSS, CSRF and clickjacking and Content Security Policy lessons each teach one defense; a threat model says which your application needs first. The method is the one in Threat Modeling for Backend Systems, applied where the boundaries sit differently.

    Verified on 2026-12-01 against the OWASP Threat Modeling Cheat Sheet, Microsoft's STRIDE description and MDN pages on the same-origin policy, cookies, CSP, subresource integrity, iframes and postMessage. No code was run for this lesson; the scores below are illustrative judgements.

    The core idea

    A threat model answers four questions: what are we working on, what can go wrong, what are we going to do about it, and did we do a good enough job? The OWASP cheat sheet lists exactly these, and adds that a model "should be maintained, updated and refined alongside the system" rather than made once.

    For a front end, two rules decide most of the answers:

    1. Whatever reaches the browser belongs to the user. They can read it, change it and replay it. A check in the client is a convenience for honest users; the server must enforce the same rule.
    2. Whatever runs in your page has your page's power. A script from your own bundle, from a vendor or from an attacker's injection can all read the screen and send requests with the user's cookies. The browser does not tell them apart.

    Three illustrations run through the lesson, each labelled:

    • Minimal example: one component that shows an order note typed by someone else.
    • Realistic example: the orders dashboard of a shop, described next.
    • Failure example: a vendor script that is changed after you reviewed it.

    The realistic example. https://shop.example/account is a single-page application. A signed-in shopper sees their orders, edits a delivery address, and saves a card through a payment form hosted in an iframe from a payment provider. The page also loads an analytics script and a support-chat widget from two vendors, and calls an API at https://api.shop.example. The shop, its pages and the API are an invented teaching example.

    Trust boundaries in the browser

    OWASP says a model should give a clear view of "trust boundaries, data flows, data stores, processes" because these "often represent possible attack points". At the back end the boundary is usually a network edge. In the browser it runs through one page.

    MDN defines two URLs as the same origin when scheme, host and port match, and says cross-origin reads are typically disallowed while cross-origin writes (links, redirects, form submissions) and embedding (scripts, images, iframes) are typically allowed. Read that as a map: another site can make your user's browser send a request, and you can include a script from another origin, but documents cannot read each other. A script you include is not "another document"; it runs inside yours.

    Trust zones of the orders dashboardShopper to Dashboard code (F1 input, clicks); Dashboard code to Storage (F2 session); Vendor scripts to Dashboard code (F3 runs inside); Dashboard code to Payment iframe (F4 messages); Dashboard code to Shop API (F5 requests)THE USER'S MACHINE: NOT YOURSYOUR ORIGINOTHER ORIGINSYOUR SERVERSShopper: owns the deviceShopperowns the deviceDashboard code: your bundleDashboard codeyour bundleStorage: cookies, tokensStoragecookies, tokensVendor scripts: chat, analyticsVendor scriptschat, analyticsPayment iframe: provider originPayment iframeprovider originShop API: api.shop.exampleShop APIapi.shop.exampleF1 input, clicksF2 sessionF3 runs insideF4 messagesF5 requests

    Figure 1. Four zones and five flows. How to read this: the shopper and the browser storage are outside your control, the vendor scripts are outside it too although they run in your page (the red dashed line F3), and only the API is on servers you run. Every flow that crosses a zone edge, F1 to F5, is a place to ask what can go wrong.

    What an attacker wants from a front end

    Start from assets, because a front end holds few of them and they are valuable.

    Asset Why it matters
    The signed-in session (a cookie or a token) Whoever holds it acts as the shopper
    What is on screen: orders, addresses, names Personal data, readable by any script in the page
    The ability to act: buttons and API calls A script can click and call as the user without ever seeing a password
    Page integrity: what the shopper believes they are looking at A fake form or a hidden overlay turns trust into a mistake
    The payment fields The most sensitive input the page touches

    The second and third rows are the ones people forget. A script in the page need not steal anything: MDN says an HttpOnly cookie, which JavaScript cannot read through Document.cookie, "will still be sent with JavaScript-initiated requests" such as fetch(). HttpOnly stops the cookie being carried away, but the script can still act while the tab is open.

    Finding threats with STRIDE

    STRIDE is a six-part prompt list. OWASP pairs each category with the property it violates: spoofing with authentication, tampering with integrity, repudiation with accounting, information disclosure with confidentiality, denial of service with availability, and elevation of privilege with authorization. In a browser application they tend to mean:

    Letter In the browser Dashboard example Usual defense
    Spoofing Someone pretends to be the user, or the page pretends to be something it is not A forged cross-site request; a transparent frame over a button SameSite cookies, tokens, frame-ancestors (CSRF and clickjacking)
    Tampering Script or markup that was not yours changes the page or its requests An order note rendered as HTML; a changed vendor file Render data as text, CSP, subresource integrity
    Repudiation A record kept only in the client can be edited "I accepted the terms" stored in the browser Record the event on the server
    Information disclosure Data moves to a reader who should not have it A token in web storage that any script can read; a postMessage sent with a wildcard target HttpOnly cookies, exact target origins
    Denial of service The page stops being usable A vendor script that blocks or breaks rendering Load it so a failure does not block, degrade without it
    Elevation of privilege The user reaches a function they should not An "admin" menu hidden in the UI while the API answers anyone Enforce permission on the server

    Minimal example. A comment on an order says <script>alert(1)</script>. If the component builds HTML from the note, the browser runs it; if it sets the note as text, the browser shows the characters.

    sequenceDiagram accTitle: The same order note rendered two ways accDescr: A note containing a script tag is stored by the API. The dashboard first renders it as markup, so the browser runs the script with the page's power. Then the dashboard renders it as text, so the browser only displays the characters. participant A as Note author participant S as Shop API participant D as Dashboard participant B as Shopper's browser A->>S: save note with a script tag S-->>D: note text, unchanged D->>B: render as markup Note over B: script runs inside the page D->>B: render as text Note over B: characters are displayed, nothing runs

    Figure 2. One note, two outcomes. How to read this: the data did not change; the way the dashboard handed it to the browser did. That is the trust-boundary question in one line: where does text from another person become code?

    MDN is direct about what a CSP does not replace: "Setting a CSP is not an alternative to sanitizing input. Websites should sanitize input and set a CSP, providing defense in depth against XSS."

    Ranking and choosing responses

    OWASP says ranking should be based on the product of likelihood and impact, admits both are hard to estimate and that the product ignores the effort to fix. Its responses are mitigate, eliminate, transfer and accept; transfer "does not itself reduce the likelihood or harmful consequences".

    Realistic example. Likelihood (L) and impact (I) are 1 to 3, scored by judgement for this teaching dashboard; the score is L times I.

    ID STRIDE Flow Threat L x I Response
    T1 E F5 "Admin" actions hidden in the UI but not checked by the API 3 x 3 = 9 Enforce permission per request on the server (auth flows)
    T2 T F1, F5 Order note or product text rendered as markup 2 x 3 = 6 Render as text; sanitise any HTML you must allow; add a CSP
    T3 I F2 Session token kept where any script can read it 2 x 3 = 6 HttpOnly, Secure cookie; limit scripts in the page
    T4 T F3 A vendor script does more than it was included for 2 x 3 = 6 Fewer scripts; isolate what you can in a sandboxed iframe; allow-list sources
    T5 S F5 A forged cross-site request changes the delivery address 2 x 2 = 4 SameSite, a token or Origin check
    T6 I F4 A message with card context goes to, or is accepted from, the wrong origin 2 x 2 = 4 Exact targetOrigin; check event.origin and the message shape
    T7 S F1 The page is framed by another site to trick a click 1 x 2 = 2 frame-ancestors 'none' unless embedding is wanted
    T8 R F1 Consent recorded only in the browser 2 x 1 = 2 Store the event, time and version on the server

    Read it as a work list. T1 comes first and no front-end change fixes it, which is the first rule at work: the top threat is a missing server check. Three rows tie at 6, so break the tie by cost and overlap: a CSP helps T2, T3 and T4 at once, because it controls what a page may load.

    Each defense is bounded. MDN says SameSite=Lax sends a cookie on cross-site requests only for top-level navigations using a safe method (so not POST, PUT or DELETE), and that some browsers apply Lax by default when the attribute is missing, without naming which, so set it yourself. The __Host- prefix requires Secure, no Domain and Path=/, but offers no assurance on browsers that do not support prefixes.

    Attack trees for the goal that matters

    OWASP recommends attack trees for "a high-value attacker goal or multi-step attack": start with the goal and decompose the paths to it. For a front end the goal is usually "act as the shopper".

    flowchart TD accTitle: Attack tree for acting as the shopper accDescr: The goal is to act as the shopper without their password. One branch is to run a script in the page, either through unescaped data or through a changed vendor script. A second branch is to make the browser send a forged request. A third is to read a stored credential, which needs a script in the page first. Each leaf lists the control that blocks it. G["Goal: act as the shopper"] --> A["Run a script in the page"] G --> B["Make the browser send a request"] G --> C["Read a stored credential"] A --> A1["Unescaped data
    blocked by: render as text, CSP"] A --> A2["Changed vendor script
    blocked by: fewer scripts, sandbox, allow-list"] B --> B1["Forged cross-site request
    blocked by: SameSite, token, Origin check"] C --> C1["Token in web storage
    blocked by: HttpOnly cookie"] C --> A

    Figure 3. Three ways to the same goal. How to read this: the arrow from the credential branch back to "Run a script" shows the dependency: reading storage needs script in the page first. That makes script execution the node to defend hardest, since closing it also closes the third branch.

    Third-party code is a boundary too

    MDN says subresource integrity lets a browser verify that fetched resources, for example from a CDN, "are delivered without unexpected manipulation": a hash is compared, and on a mismatch the browser refuses to load the file. Cross-origin use needs the crossorigin attribute because it relies on CORS. Integrity covers a file that is supposed to stay the same. A chat widget that loads the vendor's latest script cannot be pinned, because the file is meant to change; for that the iframe sandbox attribute applies. An empty value applies all restrictions, tokens lift them one by one, and MDN warns that allow-scripts plus allow-same-origin on same-origin content lets the embedded document remove the sandbox. Dependency and supply-chain security and third-party scripts and iframe sandboxing are lessons of their own in this course.

    The failure example. A vendor changes its widget script after the review that approved it. Nothing in your repository changed, so no review or test noticed, yet code with the page's full power now behaves differently. The answer is not to trust the review but to shrink the power: isolate the widget, allow only the origins you expect, and limit the data it can see.

    For the payment iframe, MDN's postMessage rule applies: add no listener if you expect no messages; otherwise "always verify the sender's identity" using origin, verify the message syntax, and send to an exact target origin, "not *".

    flowchart TD accTitle: Where a third-party script should run accDescr: For a vendor script, first ask whether it needs the page's data. If not, run it on a page without personal data. If it does, ask whether it can work inside a sandboxed iframe. If so, use the iframe with messages. If not, include it in the page, allow-list its origin and review it as part of the application. Q1{"Does it need the
    page's data?"} -->|no| P1["Page without personal data"] Q1 -->|yes| Q2{"Can it work
    in a sandboxed iframe?"} Q2 -->|yes| P2["Iframe plus exact-origin messages"] Q2 -->|no| P3["In the page, allow-listed,
    reviewed like your own code"]

    Figure 4. A decision for each vendor script. How to read this: the further down the chart, the more power the script holds, so each step down needs a reason and an owner.

    Trade-offs

    Choice Gain Cost Wrong when
    Session in an HttpOnly cookie Script cannot carry the session away Needs CSRF defenses; cookies go with every request The API is on another site and cookies will not flow
    Vendor script in the page Simple, full features Runs with the page's power It sees personal data it does not need
    Vendor widget in a sandboxed iframe Less power, contained failure Less integration, messaging to design The widget needs the page's DOM to work
    Strict CSP Defense in depth against injection Slower to roll out; breaks inline code You cannot yet list your script sources
    Subresource integrity Detects a changed static file Breaks on every legitimate update The file is meant to change

    Build it

    There is no lab for this lesson: a threat model is a diagram and a table, and the useful artefact is the list of changes it produces. Draw your own application's zones as in Figure 1, number each flow that crosses a zone edge, and fill a table like the one above.

    In practice: adding a chat widget to the orders dashboard

    This is a realistic scenario, not a case history.

    This is an educational scenario on the invented dashboard above. Every number is illustrative.

    The situation

    Support asks for a chat widget on /account so shoppers can ask about an order without leaving the page. The vendor's instructions are one script tag.

    Starting architecture

    Zones as in Figure 1, with the analytics script already in the page. The widget would add a second vendor script to the page that shows orders and addresses.

    Options considered

    Option Behaviour Cost Risk
    A. Script tag as instructed Widget runs in the account page One line A vendor change reaches order data (T4)
    B. Sandboxed iframe Widget isolated from the dashboard Context passed by message Messaging mistakes (T6)
    C. Help page only Account page keeps its zones Shoppers must navigate None new

    The decision

    Option C first, option B later. The help page holds no order data, so the vendor script adds no new asset to expose. If support needs order context, the dashboard sends an order number by message with an exact target origin, and the widget fetches nothing from the dashboard.

    Rollout and verification

    Update the model: a new zone, a new flow, new rows. Ship the widget on the help page behind a flag. Verify that the account page does not load the vendor's origin and that the policy still lists only expected origins.

    The 2 a.m. failure

    An alert shows the help page's error rate rising: the vendor's script fails to load. Chat is unavailable, but the account page is unaffected because the widget was never in it. First checks: the vendor's status page and whether the page shows a "contact us" link instead. Mitigation: a flag hides the widget and shows the link. Follow-up: show the link by default and review third parties quarterly.

    The other side of this topic

    The back end sees the same shopper through gateways, services and data stores, with boundaries at network edges; its threats are treated in Threat Modeling for Backend Systems. The two models meet at flow F5: the front end can reduce bad requests, and only the server can refuse them.

    Architect's notes

    • Model the page, not just the network. The boundary that matters most is inside the tab.
    • Treat every script as part of your application, and decide what each may see.
    • Enforce where the user cannot edit. Hiding a button is not a permission check.

    Common mistakes

    • Treating the client check as the control. The user can bypass anything in the browser.
    • Believing HttpOnly ends script risk. It stops theft of the cookie, not use of the session.
    • Using * as a postMessage target. MDN warns it can disclose data to a malicious site.
    • Modelling once. OWASP says a model should be maintained alongside the system.

    Key takeaways

    • Start from the browser's zones: the user's machine, your origin, other origins and your servers.
    • Whatever reaches the browser belongs to the user; whatever runs in the page has the page's power.
    • Tie each STRIDE letter to a concrete flow across a boundary, then rank by likelihood times impact.
    • The top threat is often a missing server check that no front-end code can fix.
    • Redo the model when a feature adds a script, a frame or a data flow.

    Practice exercises

    Exercise 1 (45 min). Draw the zones and flows of an application you know and write one STRIDE question per flow that crosses a zone edge.

    Exercise 2 (40 min). Build an attack tree for "read another shopper's address". Mark which leaves a front-end change can close and which only the server can.

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments