Repository: flutter
Issue: [web][CanvasKit][skwasm] Cookie-based authentication for Network images not possible
Labels: platform-web,a: images,has reproducible steps,P2,team-web,triaged-web,found in release: 3.22,found in release: 3.23

### Steps to reproduce

1. Download the example project:
[image_cookies.zip](https://github.com/user-attachments/files/15871460/image_cookies.zip)
2. Generate a trusted SSL certificate for localhost
3. Run the server
4. Run the app


### Expected results

The `/authenticated_image` request succeeds as it can validate the passed Cookies.

### Actual results

The cookies are not sent as part of the `/authenticated_image` request, and thus, authenticating failed.

### Code sample

Full runnable example: [image_cookies.zip](https://github.com/user-attachments/files/15871460/image_cookies.zip)

<details open><summary>Code sample</summary>

`main.dart`:
```dart
import 'package:dio/browser.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Web Cookie Authentication'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool _loaded = false;

  @override
  void initState() {
    super.initState();
    _getAuthCookies();
  }

  void _getAuthCookies() async {
    final dio = Dio();
    var adapter = BrowserHttpClientAdapter();
    adapter.withCredentials = true;
    dio.httpClientAdapter = adapter;
    await dio.getUri(Uri.parse('https://localhost:3000'));
    if (!mounted) return;
    setState(() {
      _loaded = true;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            if (!_loaded)
              const Text(
                'Loading',
              ),
            if (_loaded)
              Image.network('https://localhost:3000/authenticated_image')
          ],
        ),
      ),
    );
  }
}
```

`server.ts`:
```ts
import express from 'express';
import cors from 'cors';
import * as fs from 'fs';
import cookieParser from "cookie-parser";
import * as https from 'node:https';

const key = fs.readFileSync('./cert/localhost/localhost.decrypted.key');
const cert = fs.readFileSync('./cert/localhost/localhost.crt');

const app = express();

app.use(
  cors({
    origin: /http:\/\/localhost:\d{4,5}/,
    credentials: true,
  })
);
app.use(cookieParser())

app.get('/', (req, res) => {
  res.cookie('Auth-Cookie', "valid_request", {
    sameSite: 'none',
    maxAge: 1000 * 60 * 60,
    secure: true,
  });
  res.send('<img src="/authenticated_image">');
});

app.get('/authenticated_image', (req, res) => {
  const authCookie = req.cookies['Auth-Cookie'];
  if (authCookie === 'valid_request') {
    fs.createReadStream('./src/favicon.png').pipe(res);
  } else {
    res.status(403).send('Unauthenticated');
  }
});

const server = https.createServer({key, cert}, app);
const port = 3000;
server.listen(port, () => {
  console.log(`Server is listening on https://localhost:${port}`);
});
```
</details>


### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel [user-branch], 3.23.0-13.0.pre.243, on macOS 14.3 23D56 darwin-arm64, locale en-DE)
    ! Flutter version 3.23.0-13.0.pre.243 on channel [user-branch] at /Users/dennis/develop/bin/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Upstream repository https://github.com/simpleclub-extended/flutter.git is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to https://github.com/simpleclub-extended/flutter.git to dismiss this error.
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2024.1)
[✓] VS Code (version 1.88.1)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 2 categories.
```

Note: I'm on a custom branch as I've experimented with a fix.
At the time of testing, no changes were made to Flutter. :)

</details>