<?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>289171</bug_id>
          
          <creation_ts>2025-03-05 08:42:26 -0800</creation_ts>
          <short_desc>REGRESSION (Safari 18.2): crypto.subtle.encrypt broken for &apos;AES-GCM&apos; : OperationError</short_desc>
          <delta_ts>2025-03-12 13:49:25 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>Safari 18</version>
          <rep_platform>Mac (Apple Silicon)</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>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>kim.dunagan.78789</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>nitinmahendru</cc>
    
    <cc>pascoe</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>wilander</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2100632</commentid>
    <comment_count>0</comment_count>
    <who name="">kim.dunagan.78789</who>
    <bug_when>2025-03-05 08:42:26 -0800</bug_when>
    <thetext>crypto.subtle.encrypt fails to encrypt safari 18.2 on macOS. Error message is &quot;The operation failed for an operation-specific reason&quot;

AES-GCM encryption fails for the following steps.  Tested in the dev console in safari on safari preview Release 209 (Safari 18.2, WebKit 19621.1.6)
    
var key = await crypto.subtle.generateKey(
          { name: &apos;AES-GCM&apos;, length: 256 },
          true, 
          [&apos;encrypt&apos;, &apos;decrypt&apos;]
        );

var iv = new TextEncoder()
          .encode(&apos;hi friends! Happy day to you&apos;)
          .slice(0, 11);

var data = new TextEncoder().encode(
          &apos;Some random text&apos;
        );

var failure = await crypto.subtle
          .encrypt(
            { name: &apos;AES-GCM&apos;, iv: iv },
            key,
            data
          );

Error message in dev console: 
OperationError: The operation failed for an operation-specific reason
     { code: 0,
       message: &quot;The operation failed for an operation-specific reason&quot;,
       name: &quot;OperationError&quot;,
       stack: &quot;&quot;
     }</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2100803</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2025-03-05 17:07:23 -0800</bug_when>
    <thetext>Thank you for the report! Just to clarify, when you say that this is happening in Safari 18.2, do you mean that it worked as expected earlier, or that this was the only version tested?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2100965</commentid>
    <comment_count>2</comment_count>
    <who name="">kim.dunagan.78789</who>
    <bug_when>2025-03-06 06:47:06 -0800</bug_when>
    <thetext>Versions tested
* Successful encryption: Safari Version 17.4 (19618.1.15.11.12) (my mac&apos;s safari) (My mac is on Sonoma )
* Successful encryption: Safari Version 18.1 on Sequoia (Used remote desktop safari on BrowserStack) (Unfortunately, I can&apos;t get the exact version due to browser stack restrictions. The navigator.useragent is &apos;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Safari/605.1.15&quot;&apos; 

* Failed Encryption: Safari 18.2, WebKit 19621.1.6</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2101001</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-03-06 08:51:31 -0800</bug_when>
    <thetext>&lt;rdar://problem/146395205&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2101023</commentid>
    <comment_count>4</comment_count>
    <who name="Nitin Mahendru">nitinmahendru</who>
    <bug_when>2025-03-06 09:47:33 -0800</bug_when>
    <thetext>Thank you for the report!
The problem is the iv length and the minimum length requirement was changed in 18.2 safari. Considering 18.2 has been out for some time and this is the first report we are hearing, I would request if you can use 12 byte or higher IVs ?
 If you change your iv generation code to the below, it will work. 
`var iv = new TextEncoder()
          .encode(&apos;hi friends! Happy day to you&apos;)
          .slice(0, 12);
`
As per the recommendation here https://developer.mozilla.org/en-US/docs/Web/API/AesGcmParams, you should use 12 bytes(96 bits) or higher.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2101053</commentid>
    <comment_count>5</comment_count>
    <who name="">kim.dunagan.78789</who>
    <bug_when>2025-03-06 10:54:34 -0800</bug_when>
    <thetext>Thank you, and sorry for bothering you two. You&apos;re the best Nitin! Thank you as well Alexey! Have a wonderful day</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2101054</commentid>
    <comment_count>6</comment_count>
    <who name="">kim.dunagan.78789</who>
    <bug_when>2025-03-06 10:55:08 -0800</bug_when>
    <thetext>oh, I guess I should say that I just tested using 12 bytes and it worked as expected on safari 18.2</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2101102</commentid>
    <comment_count>7</comment_count>
    <who name="Nitin Mahendru">nitinmahendru</who>
    <bug_when>2025-03-06 12:32:23 -0800</bug_when>
    <thetext>great to hear that!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2102094</commentid>
    <comment_count>8</comment_count>
    <who name="Nitin Mahendru">nitinmahendru</who>
    <bug_when>2025-03-10 17:58:36 -0700</bug_when>
    <thetext>Will make a change so that we also allow &lt; 12 byte IV.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2102376</commentid>
    <comment_count>9</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-03-11 16:15:32 -0700</bug_when>
    <thetext>Committed 291981@main (07989805db41): &lt;https://commits.webkit.org/291981@main&gt;

Reviewed commits have been landed. Closing PR #42234 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2102661</commentid>
    <comment_count>10</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-03-12 13:49:25 -0700</bug_when>
    <thetext>Committed 289651.270@safari-7621-branch (e7903dee80f9): &lt;https://commits.webkit.org/289651.270@safari-7621-branch&gt;

Reviewed commits have been landed. Closing PR #2786 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>