Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/playwright-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
run: pnpm --filter @sam-monorepo/playwright test
env:
BASE_URL: ${{ vars.BASE_URL }}
PLAYWRIGHT_CUSTOM_HEADER_NAME: ${{ vars.PLAYWRIGHT_CUSTOM_HEADER_NAME }}
PLAYWRIGHT_CUSTOM_HEADER_VALUE: ${{ secrets.PLAYWRIGHT_CUSTOM_HEADER_VALUE }}

- name: Upload test report
uses: actions/upload-artifact@v4.6.2
Expand Down
2 changes: 2 additions & 0 deletions pnpm-monorepo/apps/playwright/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
BASE_URL=
PLAYWRIGHT_CUSTOM_HEADER_NAME=
PLAYWRIGHT_CUSTOM_HEADER_VALUE=
14 changes: 14 additions & 0 deletions pnpm-monorepo/apps/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { defineConfig } from "@playwright/test";
import "dotenv/config";

// Build custom HTTP headers object if both name and value are provided
const extraHTTPHeaders: Record<string, string> = {};
const headerName = process.env.PLAYWRIGHT_CUSTOM_HEADER_NAME;
const headerValue = process.env.PLAYWRIGHT_CUSTOM_HEADER_VALUE;

if (headerName && headerValue) {
// Basic validation: HTTP header names should be alphanumeric with hyphens/underscores
if (!/^[a-zA-Z0-9_-]+$/.test(headerName)) {
throw new Error(`Invalid HTTP header name: ${headerName}. Header names must contain only alphanumeric characters, hyphens, and underscores.`);
Comment on lines +10 to +12
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header name validation regex allows underscores, but RFC 7230 specifies that HTTP header field names should only contain alphanumeric characters and hyphens. Underscores in header names can cause compatibility issues with some HTTP servers and proxies. Consider removing _ from the regex pattern or documenting this deviation from the standard.

Suggested change
// Basic validation: HTTP header names should be alphanumeric with hyphens/underscores
if (!/^[a-zA-Z0-9_-]+$/.test(headerName)) {
throw new Error(`Invalid HTTP header name: ${headerName}. Header names must contain only alphanumeric characters, hyphens, and underscores.`);
// Basic validation: HTTP header names should be alphanumeric with optional hyphens
if (!/^[A-Za-z0-9-]+$/.test(headerName)) {
throw new Error(`Invalid HTTP header name: ${headerName}. Header names must contain only alphanumeric characters and hyphens.`);

Copilot uses AI. Check for mistakes.
}
extraHTTPHeaders[headerName] = headerValue;
}

export default defineConfig({
testDir: "./tests",
fullyParallel: true,
Expand All @@ -11,5 +24,6 @@ export default defineConfig({
use: {
baseURL: process.env.BASE_URL,
trace: "on-first-retry",
...(Object.keys(extraHTTPHeaders).length > 0 && { extraHTTPHeaders }),
},
});
Loading