Skip to content

[Bug][chromium]: When enabling tracing with snapshots, the protected HEAD request causes credential dialog to open #35891

Closed as not planned
@saw-jan

Description

@saw-jan

Version

1.52.0

Steps to reproduce

I couldn't find other way to reproduce this. So, here's my setup:

  1. Start ocis server. Simple docker compose file
    services:
      ocis:
        image: owncloud/ocis:latest
        ports:
          - 9200:9200
        environment:
          OCIS_URL: https://localhost:9200
          IDM_ADMIN_PASSWORD: admin
          OCIS_INSECURE: true
          OCIS_LOG_LEVEL: error
        entrypoint: /bin/sh
        command: ['-c', 'ocis init || true; ocis server']
  2. Start the following test in headed mode:
    import { test, chromium } from '@playwright/test'
    
    test('download', async () => {
      const browser = await chromium.launch()
      const context = await browser.newContext()
      await context.tracing.start({ screenshots: false, snapshots: true, sources: false })
      const page = await context.newPage()
      await page.goto('https://localhost:9200')
      await page.locator('#oc-login-username').fill('admin')
      await page.locator('#oc-login-password').fill('admin')
      await Promise.all([
        page.waitForResponse(
          (resp) =>
            resp.url().endsWith('/token') && resp.status() === 200 && resp.request().method() === 'POST'
        ),
        page.locator('button[type="submit"]').click()
      ])
      await page.locator('#web-content').waitFor()
      await page.pause()
      await context.tracing.stop({ path: 'trace.zip' })
    })
  3. From the running ocis UI, upload an image
  4. Open the image
  5. Download the image
    Image

Expected behavior

Browser credential dialog should not be opened.

Actual behavior

Browser credential dialog appears

Image

Additional context

Note

we should not try to get the body for HEAD requests as HEAD request will not send the body (see rfc)

const getResponseBody = async () => {
const contentLengthHeader = Object.entries(responsePayload.headers).find(header => header[0].toLowerCase() === 'content-length');
const expectedLength = contentLengthHeader ? +contentLengthHeader[1] : undefined;
const session = request.session;
const response = await session.send('Network.getResponseBody', { requestId: request._requestId });
if (response.body || !expectedLength)
return Buffer.from(response.body, response.base64Encoded ? 'base64' : 'utf8');
// Make sure no network requests sent while reading the body for fulfilled requests.
if (request._route?._fulfilled)
return Buffer.from('');
// For <link prefetch we are going to receive empty body with non-empty content-length expectation. Reach out for the actual content.
const resource = await session.send('Network.loadNetworkResource', { url: request.request.url(), frameId: this._serviceWorker ? undefined : request.request.frame()!._id, options: { disableCache: false, includeCredentials: true } });

This doesn't happen with Firefox and Webkit browsers

For chromium, the solution could be to return empty body early for HEAD requests from getResponseBody of crNetworkManager.ts

const getResponseBody = async () => { 
  if (request.request.method() === 'HEAD') {
    return Buffer.from('');
  }
...

Environment

System: `Ubuntu 22.04`
Node: `20.18.1`

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions