Skip to content

Commit

Permalink
[Local Network Access] Rename private to local in request.cc
Browse files Browse the repository at this point in the history
In WICG/private-network-access#91, we decided to
rename (public, private, local) IP address spaces to (public, local,
loopback). The spec has already been renamed in
WICG/private-network-access#97.
New spec:
https://wicg.github.io/local-network-access/#ip-address-space-heading

This CL renames the string representation in request.cc. It also updates
a mixed content wpt because it uses targetAddressSpace defined in
Request.

There are so many places to rename, so during the process, there will
inevitably be inconsistencies. Hopefully, we shall resolve all of them
soon.

Bug: 1418287
Change-Id: Ib01eb5385626c410d2b5f2bba4a67b86a28380d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4317043
Reviewed-by: Camille Lamy <clamy@chromium.org>
Commit-Queue: Jonathan Hao <phao@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1115707}
  • Loading branch information
johnathan79717 authored and chromium-wpt-export-bot committed Mar 10, 2023
1 parent 7430bc2 commit 4af24bc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// META: script=/common/utils.js
// META: script=resources/support.sub.js
//
// Spec: https://wicg.github.io/private-network-access
// Spec: https://wicg.github.io/local-network-access
//
// These tests verify that secure contexts can fetch non-secure subresources
// from more private address spaces, avoiding mixed context checks, as long as
// from more local address spaces, avoiding mixed context checks, as long as
// they specify a valid `targetAddressSpace` fetch option that matches the
// target server's address space.

Expand All @@ -16,9 +16,9 @@ setup(() => {
// Given `addressSpace`, returns the other three possible IP address spaces.
function otherAddressSpaces(addressSpace) {
switch (addressSpace) {
case "local": return ["unknown", "private", "public"];
case "private": return ["unknown", "local", "public"];
case "public": return ["unknown", "local", "private"];
case "loopback": return ["unknown", "local", "public"];
case "local": return ["unknown", "loopback", "public"];
case "public": return ["unknown", "loopback", "local"];
}
}

Expand Down Expand Up @@ -169,64 +169,66 @@ function makeNoBypassTests({ source, target }) {
},
fetchOptions: { targetAddressSpace: correctAddressSpace },
expected: FetchTestResult.FAILURE,
}), prefix + 'not a private network request.');
}), prefix + 'not a local network request.');
}

// Source: local secure context.
// Source: loopback secure context.
//
// Fetches to the local and private address spaces cannot use
// Fetches to the loopback and local address spaces cannot use
// `targetAddressSpace` to bypass mixed content, as they are not otherwise
// blocked by Private Network Access.
// blocked by Local Network Access.

makeNoBypassTests({ source: "local", target: "local" });
makeNoBypassTests({ source: "local", target: "private" });
makeNoBypassTests({ source: "local", target: "public" });
makeNoBypassTests({ source: "loopback", target: "loopback" });
makeNoBypassTests({ source: "loopback", target: "local" });
makeNoBypassTests({ source: "loopback", target: "public" });

// Source: private secure context.
// Source: local secure context.
//
// Fetches to the local address space requires the right `targetAddressSpace`
// Fetches to the loopback address space requires the right `targetAddressSpace`
// option, as well as a successful preflight response carrying a PNA-specific
// header.
//
// Fetches to the private address space cannot use `targetAddressSpace` to
// bypass mixed content, as they are not otherwise blocked by Private Network
// Fetches to the local address space cannot use `targetAddressSpace` to
// bypass mixed content, as they are not otherwise blocked by Local Network
// Access.

makeTests({ source: "private", target: "local" });
makeTests({ source: "local", target: "loopback" });

makeNoBypassTests({ source: "private", target: "private" });
makeNoBypassTests({ source: "private", target: "public" });
makeNoBypassTests({ source: "local", target: "local" });
makeNoBypassTests({ source: "local", target: "public" });

// Source: public secure context.
//
// Fetches to the local and private address spaces require the right
// Fetches to the loopback and local address spaces require the right
// `targetAddressSpace` option, as well as a successful preflight response
// carrying a PNA-specific header.

makeTests({ source: "public", target: "loopback" });
makeTests({ source: "public", target: "local" });
makeTests({ source: "public", target: "private" });

makeNoBypassTests({ source: "public", target: "public" });

// These tests verify that documents fetched from the `local` address space yet
// carrying the `treat-as-public-address` CSP directive are treated as if they
// had been fetched from the `public` address space.
// These tests verify that documents fetched from the `loopback` address space
// yet carrying the `treat-as-public-address` CSP directive are treated as if
// they had been fetched from the `public` address space.

promise_test_parallel(t => fetchTest(t, {
source: {
server: Server.HTTPS_LOCAL,
treatAsPublic: true,
},
target: {
server: Server.HTTP_LOCAL,
behavior: {
preflight: PreflightBehavior.optionalSuccess(token()),
response: ResponseBehavior.allowCrossOrigin(),
},
},
fetchOptions: { targetAddressSpace: "private" },
expected: FetchTestResult.FAILURE,
}), 'https-treat-as-public to http-local: wrong targetAddressSpace "private".');
promise_test_parallel(
t => fetchTest(t, {
source: {
server: Server.HTTPS_LOCAL,
treatAsPublic: true,
},
target: {
server: Server.HTTP_LOCAL,
behavior: {
preflight: PreflightBehavior.optionalSuccess(token()),
response: ResponseBehavior.allowCrossOrigin(),
},
},
fetchOptions: {targetAddressSpace: 'local'},
expected: FetchTestResult.FAILURE,
}),
'https-treat-as-public to http-loopback: wrong targetAddressSpace "local".');

promise_test_parallel(t => fetchTest(t, {
source: {
Expand All @@ -240,9 +242,9 @@ promise_test_parallel(t => fetchTest(t, {
response: ResponseBehavior.allowCrossOrigin(),
},
},
fetchOptions: { targetAddressSpace: "local" },
fetchOptions: { targetAddressSpace: "loopback" },
expected: FetchTestResult.SUCCESS,
}), "https-treat-as-public to http-local: success.");
}), "https-treat-as-public to http-loopback: success.");

promise_test_parallel(t => fetchTest(t, {
source: {
Expand All @@ -256,9 +258,9 @@ promise_test_parallel(t => fetchTest(t, {
response: ResponseBehavior.allowCrossOrigin(),
},
},
fetchOptions: { targetAddressSpace: "local" },
fetchOptions: { targetAddressSpace: "loopback" },
expected: FetchTestResult.FAILURE,
}), 'https-treat-as-public to http-private: wrong targetAddressSpace "local".');
}), 'https-treat-as-public to http-local: wrong targetAddressSpace "loopback".');

promise_test_parallel(t => fetchTest(t, {
source: {
Expand All @@ -272,6 +274,6 @@ promise_test_parallel(t => fetchTest(t, {
response: ResponseBehavior.allowCrossOrigin(),
},
},
fetchOptions: { targetAddressSpace: "private" },
fetchOptions: { targetAddressSpace: "local" },
expected: FetchTestResult.SUCCESS,
}), "https-treat-as-public to http-private: success.");
}), "https-treat-as-public to http-local: success.");
24 changes: 12 additions & 12 deletions fetch/private-network-access/resources/support.sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ async function postMessageAndAwaitReply(target, message) {
// Maps protocol (without the trailing colon) and address space to port.
const SERVER_PORTS = {
"http": {
"local": {{ports[http][0]}},
"private": {{ports[http-private][0]}},
"loopback": {{ports[http][0]}},
"local": {{ports[http-private][0]}},
"public": {{ports[http-public][0]}},
},
"https": {
"local": {{ports[https][0]}},
"private": {{ports[https-private][0]}},
"loopback": {{ports[https][0]}},
"local": {{ports[https-private][0]}},
"public": {{ports[https-public][0]}},
},
"ws": {
"local": {{ports[ws][0]}},
"loopback": {{ports[ws][0]}},
},
"wss": {
"local": {{ports[wss][0]}},
"loopback": {{ports[wss][0]}},
},
};

Expand Down Expand Up @@ -126,14 +126,14 @@ class Server {
};
}

static HTTP_LOCAL = Server.get("http", "local");
static HTTP_PRIVATE = Server.get("http", "private");
static HTTP_LOCAL = Server.get("http", "loopback");
static HTTP_PRIVATE = Server.get("http", "local");
static HTTP_PUBLIC = Server.get("http", "public");
static HTTPS_LOCAL = Server.get("https", "local");
static HTTPS_PRIVATE = Server.get("https", "private");
static HTTPS_LOCAL = Server.get("https", "loopback");
static HTTPS_PRIVATE = Server.get("https", "local");
static HTTPS_PUBLIC = Server.get("https", "public");
static WS_LOCAL = Server.get("ws", "local");
static WSS_LOCAL = Server.get("wss", "local");
static WS_LOCAL = Server.get("ws", "loopback");
static WSS_LOCAL = Server.get("wss", "loopback");
};

// Resolves a URL relative to the current location, returning an absolute URL.
Expand Down

0 comments on commit 4af24bc

Please sign in to comment.