Security / Field note
Browser trust reaches across application paths
Five fictional JavaScript examples distinguish cookie-path matching from origin-based access to responses, frames and storage. Cookie visibility and authenticated response access remain separate decisions.
Two applications can have different URL paths and still share a browser origin. For ordinary HTTP and HTTPS documents, that origin is defined by scheme, host and port. The path is absent from the comparison. A cookie’s Path attribute serves another purpose: it helps select which matching requests receive that cookie. It does not create a separate application trust boundary. [1] [2]
This is established web-platform behavior, reviewed on December 1, 2026. RFC 6265 described cookie path limitations in April 2011; this field note reports no new browser vulnerability or private-system incident. The five original JavaScript examples use fictional data and reserved example.test hostnames. We tested them with intercepted browser responses, without contacting those hosts or using any real account. [3]
A different folder keeps the same origin
The HTML Standard treats ordinary tuple origins as equal when their schemes, hosts and ports match. Our first example compares normalized URL origins. Changing only the path leaves the result equal. Changing the scheme, a nondefault port or the host produces a different origin. These cases deliberately avoid opaque origins and special URL schemes. [1]
const first = new URL("https://app.example.test/catalog/");
const cases = [
["https://app.example.test/records/", true],
["https://app.example.test:443/other/", true],
["https://app.example.test:8443/records/", false],
["https://other.example.test/records/", false],
["http://app.example.test/records/", false],
];
for (const [address, expected] of cases) {
const same = new URL(address).origin === first.origin;
if (same !== expected) throw new Error(address);
}For a team combining interfaces under one hostname, the useful question is which scripts and content become part of that shared origin. Separate repositories, release processes and navigation menus can remain valuable organizational choices while the browser sees the same origin. A tidy directory tree does not add another component to the origin tuple.
Match the route that receives a cookie
RFC 6265’s path-matching rules distinguish an exact match, a path ending in a slash and a prefix followed by a slash. That boundary matters: /records can match /records/summary without also matching /recordset. The next function models that comparison for the simple path strings shown. It is not a complete cookie parser. [3]
function pathMatches(cookiePath, requestPath) {
if (requestPath === cookiePath) return true;
if (!requestPath.startsWith(cookiePath)) return false;
return cookiePath.endsWith("/")
|| requestPath[cookiePath.length] === "/";
}
const cases = [
["/records", true],
["/records/", true],
["/records/summary", true],
["/recordset", false],
["/catalog/", false],
];
for (const [path, expected] of cases) {
if (pathMatches("/records", path) !== expected) {
throw new Error(path);
}
}This example uses /records without a final slash. The browser fixture below instead sets its synthetic cookie with Path=/records/. Both forms match the fixture’s /records/summary request. Matching a destination answers which request may carry the cookie; it leaves the origin’s access rules unchanged.
A hidden cookie can accompany a readable response
MDN documents that HttpOnly prevents script access through document.cookie while the cookie can still accompany JavaScript-initiated requests. Our browser fixture’s setup response creates demo_session=fictional-only with Path=/records/, Secure and HttpOnly. The example runs from /catalog/ and reads a synthetic response from the matching records path on the same origin. [2]
if (document.cookie.includes("demo_session=")) {
throw new Error("The fixture cookie should be hidden");
}
const reply = await fetch("/records/summary", {
credentials: "same-origin",
});
const body = await reply.json();
if (!reply.ok || body.marker !== "fictional-only") {
throw new Error("Expected the synthetic response");
}The fixture endpoint requires its fictional cookie. Removing that cookie produces 401 in the verification check. This is no authorization bypass: it demonstrates a response the synthetic session is allowed to read, requested by a script elsewhere on the same origin. A real server still needs to decide whether the current session may access each resource. Keeping a cookie value out of script does not settle that response-access decision.
Storage follows the origin too
MDN describes Web Storage as separated by origin. The fourth example stores a harmless marker and reads it from an unsandboxed same-origin frame at another path. The fixture intentionally permits embedding and supplies the frame page; it contains no private data. Cleanup removes both the frame and the marker. [4]
const key = "demo-path-scope";
localStorage.setItem(key, "fictional-only");
const frame = document.createElement("iframe");
const loaded = new Promise(resolve => {
frame.addEventListener("load", resolve, {once: true});
});
frame.src = "/other-area/frame";
document.body.append(frame);
try {
await loaded;
if (frame.contentWindow.localStorage.getItem(key)
!== "fictional-only") {
throw new Error("Expected shared origin storage");
}
} finally {
frame.remove();
localStorage.removeItem(key);
}This is a bounded storage observation, not proof about every embedding policy. It explains why moving a storage key behind a differently named application folder does not give that key an independent origin. Sensitive application state needs a design that accounts for all the scripts sharing the origin.
Observe the different-origin boundary separately
The last example loads a fixture frame from a different hostname. Direct access to that frame’s document raises SecurityError in our test. The HTML Standard’s origin model and cross-origin access restrictions explain why that result differs from the preceding same-origin example. The frame still loads; the observation concerns document access. [1] [4]
const frame = document.createElement("iframe");
const loaded = new Promise(resolve => {
frame.addEventListener("load", resolve, {once: true});
});
frame.src = "https://other.example.test/frame";
document.body.append(frame);
try {
await loaded;
let blocked = false;
try {
void frame.contentWindow.document;
} catch (error) {
if (error.name !== "SecurityError") throw error;
blocked = true;
}
if (!blocked) throw new Error("Expected an origin boundary");
} finally {
frame.remove();
}Cookie scope still needs its own review. RFC 6265 notes that cookies do not isolate services by port, even though a port change can distinguish browser origins. A different origin is therefore not a complete statement about cookie delivery, authentication or server permissions. Those questions should stay explicit in an application design. [3]
All five snippets passed in headless Chromium 151.0.7922.34, alongside eleven checks for path boundaries, cookie sending, HttpOnly visibility, missing-cookie denial and storage separation. Every fixture request was intercepted. Examples three through five depend on the controlled pages described above; they are not a deployable application or tests against a reader’s systems.
Our earlier field note on safe forms and page content covers related CSRF, rendering and session concerns. This narrower review adds the cohosting question: which application paths share browser authority, and what does each cookie attribute actually constrain? The answer belongs in the trust model before it becomes a reassuring folder name. [5]
Sources + further reading
Source dates describe the original material. Publication above is the date this Zyel article went live.
- HTML Living Standard: origins and same-origin accessWHATWG · Checked Dec 1, 2026
- Set-Cookie: Path and HttpOnly attributesMDN Web Docs · Checked Dec 1, 2026
- RFC 6265: path matching and cookie security considerations (April 2011)IETF / RFC Editor · Checked Dec 1, 2026
- Same-origin policy and origin-scoped storageMDN Web Docs · Checked Dec 1, 2026
- A secure login still needs safe forms and safe page contentZyel · Checked Dec 1, 2026
Reader discussion
What would you ask next?
Questions, useful corrections and thoughtful disagreement are welcome. Comments are reviewed before they appear.
No reader comments yet.