<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>281385</bug_id>
          
          <creation_ts>2024-10-12 13:12:32 -0700</creation_ts>
          <short_desc>Safari 18.0 Browser Extensions Fail to Set Cookies while expirationDate Exists</short_desc>
          <delta_ts>2025-02-01 19:58:23 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKit Extensions</component>
          <version>Safari 18</version>
          <rep_platform>All</rep_platform>
          <op_sys>macOS 15</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Critical</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>283110</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="K">khaledenglish</reporter>
          <assigned_to name="Timothy Hatcher">timothy</assigned_to>
          <cc>timothy</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2067524</commentid>
    <comment_count>0</comment_count>
    <who name="K">khaledenglish</who>
    <bug_when>2024-10-12 13:12:32 -0700</bug_when>
    <thetext>Starting from Safari 18.0, browser extensions (on iOS, iPadOS, and macOS) cannot set persistent cookies using `browser.cookies.set()` if the parameter `expirationDate` is present.

For example,

(a) this does not set cookies (the result of `browser.cookies.get(&quot;cookie_name&quot;)` is null:
=============================
browser.cookies.set({
    name: &quot;cookie_name&quot;,
    url: &quot;url_string_goes_here&quot;,
    value: &quot;jwt_token_goes_here&quot;,
    domain: &quot;domain_string_goes_here&quot;,
    secure: true,
    sameSite: &quot;lax&quot;,
    expirationDate: number_of_seconds_to_live
 });

while (b) this works:
=====================
browser.cookies.set({
    name: &quot;cookie_name&quot;,
    url: &quot;url_string_goes_here&quot;,
    value: &quot;jwt_token_goes_here&quot;,
    domain: &quot;domain_string_goes_here&quot;,
    secure: true,
    sameSite: &quot;lax&quot;,
 });

HOWEVER, (b) is now a &quot;session&quot; cookie that cannot be used to save JWTs. The moment the user closes the browser, they need to login again!

This problem started from Safari 18.0, and did not exist in Safari 17.

The current released of Safari (i.e., 18.0.1) still has this bug.

Reference: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/cookies/set</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2067525</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-10-12 13:12:40 -0700</bug_when>
    <thetext>&lt;rdar://problem/137812683&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2069717</commentid>
    <comment_count>2</comment_count>
    <who name="Timothy Hatcher">timothy</who>
    <bug_when>2024-10-21 17:17:27 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/35559</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2069791</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-10-22 06:41:56 -0700</bug_when>
    <thetext>Committed 285552@main (b66e4895df40): &lt;https://commits.webkit.org/285552@main&gt;

Reviewed commits have been landed. Closing PR #35559 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2071079</commentid>
    <comment_count>4</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-10-28 15:43:51 -0700</bug_when>
    <thetext>Committed 283286.357@safari-7620-branch (2e81a87a6d53): &lt;https://commits.webkit.org/283286.357@safari-7620-branch&gt;

Reviewed commits have been landed. Closing PR #2124 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2091277</commentid>
    <comment_count>5</comment_count>
    <who name="K">khaledenglish</who>
    <bug_when>2025-02-01 19:58:23 -0800</bug_when>
    <thetext>The issue seems to still be there. As soon as Safari quits, the cookie does not persist, and re-authentication is required. The issue has been introduced in Safari 18.0, and it still exists in the current version (18.3). The code below worked fine in previous Safari versions (15.x to 17.x).

Example:

const currentTime = Math.round(new Date().getTime() / 1000);
const expiresAfter = 60 * 60 * 24 * 7; // 7 days
const expirationDate = currentTime + expiresAfter;

browser.cookies.set({
    name: &quot;cookie_name&quot;,
    url: &quot;url_string_goes_here&quot;,
    value: &quot;token_goes_here&quot;,
    domain: &quot;domain_string_goes_here&quot;,
    secure: true,
    sameSite: &quot;lax&quot;,
    expirationDate: expirationDate
 });</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>