<?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>256054</bug_id>
          
          <creation_ts>2023-04-27 12:56:29 -0700</creation_ts>
          <short_desc>Redirection to page in extension with regexSubstitution is blocked</short_desc>
          <delta_ts>2023-09-08 10:10:41 -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>WebKit Extensions</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Emond Papegaaij">emond.papegaaij</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>achristensen</cc>
    
    <cc>luke.selker</cc>
    
    <cc>timothy</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1951633</commentid>
    <comment_count>0</comment_count>
    <who name="Emond Papegaaij">emond.papegaaij</who>
    <bug_when>2023-04-27 12:56:29 -0700</bug_when>
    <thetext>When using the declarativeNetRequest like this:

    const EXT_PAGE = chrome.runtime.getURL(&apos;/callback.html&apos;);                                                                                 
    const RULE = {                                                                                                                            
        id: 1,                                                                                                                                
        condition: {                                                                                                                          
            regexFilter: &apos;^https://www\.topicus-keyhub\.com/browser-extension-callback\.html.+$&apos;,                                             
            resourceTypes: [&apos;main_frame&apos;]                                                                                                     
        },                                                                                                                                    
        action: {                                                                                                                             
            type: &apos;redirect&apos;,                                                                                                                 
            redirect: { regexSubstitution: EXT_PAGE + &apos;#\\0&apos; }                                                                                
        }                                                                                                                                     
    };                                                                                                                                        
    chrome.declarativeNetRequest.updateDynamicRules({                                                                                         
        removeRuleIds: [RULE.id],                                                                                                             
        addRules: [RULE],                                                                                                                     
    });                                                                                                                                       

The request to the URI matched with the regex is intercepted, but the redirection fails with the following message:

Safari can’t open the page “safari-web-extension://5107FF07-6DB1-4907-BCAB-D84EB6E2655E/callback.html#https://www.topicus-keyhub.com/browser-extension-callback.html?iss=https://test.topicus-keyhub.com&amp;state=4ca2b81ed761555f4b9dad97c9d47f9ef6af239d507143b088dc32e8174a1144&amp;error=interaction_required&amp;error_description=User+interaction+required”. The error is: “Redirection to URL with a scheme that is not HTTP(S)” (:0)

We are using this method of redirection to intercept the original URI to complete an OAuth2 code flow. The intercepted page is a stub landing page and only used as a fixed redirection URI for the OAuth2 flow.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1952981</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-05-04 12:57:30 -0700</bug_when>
    <thetext>&lt;rdar://problem/108908609&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1976427</commentid>
    <comment_count>2</comment_count>
    <who name="">luke.selker</who>
    <bug_when>2023-09-08 07:42:59 -0700</bug_when>
    <thetext>Hi,


Just checking if there&apos;s been any update on this bug? It looks there may need to be a modification to this code here? https://bugs.webkit.org/show_bug.cgi?id=256054

I&apos;d really like to provide an update to our customers on when they can expect SSO to be functional in Safari. Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1976437</commentid>
    <comment_count>3</comment_count>
    <who name="Emond Papegaaij">emond.papegaaij</who>
    <bug_when>2023-09-08 08:32:35 -0700</bug_when>
    <thetext>We&apos;ve implemented a fallback to the old webRequest API for Safari. This also required us switch to manifest v2, because the webRequest API cannot be used with a non-persistent background page and v3 no longer supports persistent background pages.

I think the issue with the redirect may have to do with Safari not supporting web_accessible_resources: https://bugs.webkit.org/show_bug.cgi?id=246489

All this is getting quite a mess to get right on all browsers. This is what we ended up using:
- declarativeNetRequest wit manifest v3 on all Chromium based browsers
- webRequest with manifest v3 on Firefox
- webRequest with manifest v2 on Safari</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1976458</commentid>
    <comment_count>4</comment_count>
    <who name="">luke.selker</who>
    <bug_when>2023-09-08 10:10:41 -0700</bug_when>
    <thetext>Thanks for the quick response! Unfortunately we were using Blocking WebRequest which isn&apos;t supported in Safari, so we had not choice but to implement using DeclarativeNetRequest. Unless I&apos;m wrong, I don&apos;t think we can use both WebRequest and DeclarativeNetRequest at the same time</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>