<?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>311707</bug_id>
          
          <creation_ts>2026-04-07 22:44:00 -0700</creation_ts>
          <short_desc>CredentialsContainer: performCommonChecks() should return RefPtr&amp;lt;Document&amp;gt; instead of bool</short_desc>
          <delta_ts>2026-04-08 08:09:34 -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 Misc.</component>
          <version>WebKit Local Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</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>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Marcos Caceres">marcosc</reporter>
          <assigned_to name="Marcos Caceres">marcosc</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2197877</commentid>
    <comment_count>0</comment_count>
    <who name="Marcos Caceres">marcosc</who>
    <bug_when>2026-04-07 22:44:00 -0700</bug_when>
    <thetext>In CredentialsContainer.cpp, `get()` and `isCreate()` both call `performCommonChecks()` which checks for a null document internally via RefPtr, then immediately re-acquire the document via `Ref document = *this-&gt;document()` — relying on an implicit contract that the document is still non-null.

```cpp
void CredentialsContainer::get(CredentialRequestOptions&amp;&amp; options, CredentialPromise&amp;&amp; promise)
{
    if (!performCommonChecks(options, promise))
        return;

    Ref document = *this-&gt;document(); // unsafe: re-acquires WeakPtr without null check
    ...
}
```

The fix is to change `performCommonChecks()` to return `RefPtr&lt;Document&gt;` (or null on failure), so callers receive the document directly without re-acquiring the WeakPtr:

```cpp
void CredentialsContainer::get(CredentialRequestOptions&amp;&amp; options, CredentialPromise&amp;&amp; promise)
{
    RefPtr document = performCommonChecks(options, promise);
    if (!document)
        return;
    ...
}
```

This makes the null-safety contract explicit and eliminates the implicit assumption.

Note: This is pre-existing code. In practice the implicit contract holds soundly under WebKit&apos;s single-threaded execution model, but it violates the spirit of WebKit&apos;s safer-cpp guidelines.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2197878</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2026-04-07 22:44:07 -0700</bug_when>
    <thetext>&lt;rdar://problem/174293959&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2197892</commentid>
    <comment_count>2</comment_count>
    <who name="Marcos Caceres">marcosc</who>
    <bug_when>2026-04-08 00:03:53 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/62256</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2197987</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-04-08 08:09:32 -0700</bug_when>
    <thetext>Committed 310779@main (acecc70c2382): &lt;https://commits.webkit.org/310779@main&gt;

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

    </bug>

</bugzilla>