Skip to content

Commit

Permalink
Throw exception based on exclusions when creating sanitized cookies
Browse files Browse the repository at this point in the history
When we get a nullptr cookie from ToCanonicalCookie we assume that
there is an exception to explain the failure. We have a DCHECK to
verify such scenario. However, we only generate assertions if there is
any problem with the cookie url.

The CreateSanitizedCookie function, called to generate the return value
with the canonical cookie, performs some additional checks before
parsing the cookie string. Any error is described in as exclusion in
the CookieInclusionStatus instance. If the status has any exclusion, a
nullptr cookie is returned, but no exception is generated.

The bug 1315053 describes a scenario where we get a nullotr cookie
without an exception, violating the previously mentioned DCHECK. This
change fixes the bug by generating exceptions based on the exclusions
comment if the CreateSanitizedCookie adds any on the status instance.

This change makes our implementation spec complaint, according to what
is stated in the CookieStore-set method [1] algorithm:

"2- If r is failure, then reject p with a TypeError and abort these steps."

[1] https://wicg.github.io/cookie-store/#CookieStore-set

Bug: 1315053
Change-Id: I0ebbf727f7404391b12446a457247c4468754015
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3582579
Reviewed-by: Ayu Ishii <[email protected]>
Commit-Queue: Javier Fernandez <[email protected]>
Cr-Commit-Position: refs/heads/main@{#992339}
  • Loading branch information
javifernandez authored and chromium-wpt-export-bot committed Apr 14, 2022
1 parent 10fe1d1 commit 4e9035f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cookie-store/cookieStore_special_names.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ promise_test(async testCase => {
cookieStore.set( { name: '__Host-cookie-name', value: 'cookie-value',
path: "/path" }));
}, 'cookieStore.set with __Host- prefix a path option');

promise_test(async testCase => {
let exceptionThrown = false;
try {
await cookieStore.set(unescape('cookie-name%0D1'), 'cookie-value');
} catch (e) {
assert_equals (e.name, "TypeError", "cookieStore thrown an incorrect exception -");
exceptionThrown = true;
}
assert_true(exceptionThrown, "No exception thrown.");
}, 'cookieStore.set with malformed name.');

0 comments on commit 4e9035f

Please sign in to comment.