Skip to content

security: readiness config as script arg, cookie opt-out, per-thread Cucumber state, CI hardening (PER-8898, PER-8897, PER-8895, PER-8907) - #326

Open
Shivanshu-07 wants to merge 1 commit into
masterfrom
security/sdk-hardening
Open

Shivanshu-07 wants to merge 1 commit into
masterfrom
security/sdk-hardening

Conversation

@Shivanshu-07

@Shivanshu-07 Shivanshu-07 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • PER-8898: waitForReady now passes the merged readiness config to executeAsyncScript as arguments[0] instead of building it into the script source, the same change made in the webdriverio and puppeteer SDKs.
  • PER-8897: browser cookies are still forwarded by default, because the CLI uses them during asset discovery. Setting PERCY_DO_NOT_USE_CAPTURED_COOKIES=true (the same variable the CLI reads) now makes the SDK send no cookies. That covers the cookie jar and the document.cookie that PercyDOM.serialize captures inside cross-origin iframes. The SDK logs a warning once per process explaining the impact. The README documents the option.
  • PER-8895: PercySteps keeps the driver, the Percy instance and the regions per thread, so parallel Cucumber scenarios no longer overwrite each other. A thread that never calls setDriver still uses the last driver set, as it did before. The public API is unchanged.
  • PER-8907 (CI): test.yml uses a stricter pattern for the dispatch branch and checks it again inside the shell step. It also writes step output through $GITHUB_OUTPUT and uses $GITHUB_WORKSPACE instead of an inline expression. The Semgrep checkout no longer persists credentials. Earlier hardening (pinned actions, read-only token, input passed through env) landed in security: harden CI workflows, deps, cache and log body (PER-8891/8892/8896/8890/8889/8901/8900/8911) #322.

All error paths stay fail-open.

Tests

  • New unit tests:
    • Default forwarding sends session-like cookies unchanged.
    • With the opt-out set, no cookies are sent across two snapshots and the warning is logged exactly once.
    • With the opt-out set, iframe cookies are stripped.
    • The readiness config travels as a script argument and none of its values appear in the script source.
    • Per-thread driver/Percy isolation, the shared fallback, and no region leakage across threads.
  • Before keeping each new assertion, I broke the code it covers and confirmed the test failed: warning logged every time, opt-out ignored, iframe cookies not stripped, script source concatenation, shared-only state, no fallback, shared regions.
  • npx percy exec --testing -- mvn test with headless Firefox: 169/169 pass and the JaCoCo coverage check passes. A live snapshot logged Readiness passed, which confirms the argument-based script works in a real browser.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added an option to prevent browser cookies from being included in snapshots. When enabled, a warning is logged once; assets that require a session may not load correctly.
  • Bug Fixes
    • Improved isolation of browser sessions and snapshot regions in parallel Cucumber scenarios, preventing one scenario’s settings from affecting another.
  • Documentation
    • Added guidance on cookie forwarding, opting out, and potential effects on snapshots.

…read cucumber state, CI hardening

- waitForReady passes the merged readiness config to executeAsyncScript as
  arguments[0] instead of splicing it into the script source.
- Honour PERCY_DO_NOT_USE_CAPTURED_COOKIES=true: send no browser cookies
  (including cookies serialized inside cross-origin iframes) and warn once.
  Cookies are still forwarded by default for asset discovery.
- PercySteps keeps driver/Percy/regions per thread so parallel Cucumber
  scenarios don't overwrite each other; threads that never call setDriver
  fall back to the last driver set, as before.
- test.yml: stricter dispatch branch pattern, re-validated in the shell step,
  $GITHUB_OUTPUT instead of set-output; Semgrep checkout without persisted
  credentials.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Shivanshu-07
Shivanshu-07 requested a review from a team as a code owner November 4, 2026 09:48
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

Failed to post review comments.

GitHub was unavailable or timed out while CodeRabbit was posting the review. Please request a new review later if the pull request still needs one. This happened while posting 4 inline comments. Use @coderabbitai full review to retry the review.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML (base), Organization UI (inherited), Workspace UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Enterprise
  • Run ID: d2408671-1639-46a5-82ea-fa2be047cd70
Commits

Reviewing files that changed from the base of the PR and between 19b6083 and c197971.

Files selected for processing: 9
  • .github/workflows/Semgrep.yml
  • .github/workflows/test.yml
  • README.md
  • src/main/java/io/percy/selenium/Percy.java
  • src/main/java/io/percy/selenium/cucumber/PercySteps.java
  • src/test/java/io/percy/selenium/PercyDriverPathTest.java
  • src/test/java/io/percy/selenium/PercyLogicTest.java
  • src/test/java/io/percy/selenium/SdkTest.java
  • src/test/java/io/percy/selenium/cucumber/PercyStepsTest.java

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 5 remain after this review.

Context from checks skipped due to timeout: 1
  • GitHub Check: CodeRabbit
Walkthrough

The SDK adds a cookie-forwarding opt-out and passes readiness configuration as a script argument. Cucumber state is isolated by thread. Workflow changes validate CLI branch inputs and adjust checkout and workspace handling.

Changes: Percy SDK behavior

Layer / File(s) Summary
Cookie collection and serialization
src/main/java/io/percy/selenium/Percy.java, README.md, src/test/java/io/percy/selenium/PercyDriverPathTest.java, src/test/java/io/percy/selenium/PercyLogicTest.java
The SDK can omit cookies from serialized DOM and iframe snapshots when PERCY_DO_NOT_USE_CAPTURED_COOKIES=true. It skips cookie retrieval in this mode and logs the warning once. Tests cover default forwarding and opt-out behavior.
Readiness script argument
src/main/java/io/percy/selenium/Percy.java, src/test/java/io/percy/selenium/PercyDriverPathTest.java, src/test/java/io/percy/selenium/PercyLogicTest.java, src/test/java/io/percy/selenium/SdkTest.java
waitForReady passes readiness configuration as an argument to executeAsyncScript instead of embedding it in the script. Readiness tests use the updated call signature.

Cucumber thread-local state

Layer / File(s) Summary
Session and region handling
src/main/java/io/percy/selenium/cucumber/PercySteps.java, src/test/java/io/percy/selenium/cucumber/PercyStepsTest.java
Cucumber steps use the current thread’s session and region list, with a shared session fallback. Tests check session selection and region isolation across threads.

Workflow input and checkout changes

Layer / File(s) Summary
Checkout and branch validation
.github/workflows/Semgrep.yml, .github/workflows/test.yml
The Semgrep checkout disables persisted credentials. The test workflow validates branch names and rejects .. before cloning. Yarn output uses GITHUB_OUTPUT, and the workflow returns to the workspace through the quoted GITHUB_WORKSPACE variable.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: High

Possibly related PRs

Suggested reviewers: neha-sanse

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Linked Issues check Warning The PR implements the argument-based waitForReady call for PER-8898, but it does not implement the issue's required strict schema validation for healthcheck readiness data. For [PER-8897], the def… For PER-8898, validate the healthcheck response with a strict readiness schema before storing or merging it. For [PER-8897], remove cookie values from the default payload, filter sensitive cookies, or protect the SDK-to-CLI channel with m…
Passed Passed checks: 3 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title contains the Jira ticket IDs PER-8898, PER-8897, PER-8895, and PER-8907, which match the required pattern. It also gives a plain-English description of the main changes: readiness config pas…
Out of Scope Changes check Passed The changed files map to the four directly linked issue objectives. The readiness argument change, cookie handling and documentation, Cucumber state changes, related tests, and workflow hardening supp…
Full details: Title check

Explanation

The title contains the Jira ticket IDs PER-8898, PER-8897, PER-8895, and PER-8907, which match the required pattern. It also gives a plain-English description of the main changes: readiness config passed as a script argument, a cookie opt-out, per-thread Cucumber state, and CI hardening. The changeset matches each of these parts, so the title meets the requirement.

Full details: Out of Scope Changes check

Explanation

The changed files map to the four directly linked issue objectives. The readiness argument change, cookie handling and documentation, Cucumber state changes, related tests, and workflow hardening support those objectives. No unrelated change is demonstrated by the reviewed diff.

Full details: Linked Issues check

Explanation

The PR implements the argument-based waitForReady call for PER-8898, but it does not implement the issue's required strict schema validation for healthcheck readiness data. For [PER-8897], the default path still sends the full cookie jar, including cookie values. The opt-out does not filter cookies by default and does not add an authenticated channel. For [PER-8895], PercySteps.reset() still sets the process-wide sharedSession to null, so one thread can remove the fallback session used by other threads. For [PER-8907], .github/workflows/test.yml still clones and builds git clone --branch "$CLI_BRANCH" from workflow input. Regex validation and the .. check do not restrict the branch to a vetted SHA or remove the arbitrary branch override.

Resolution

For PER-8898, validate the healthcheck response with a strict readiness schema before storing or merging it. For [PER-8897], remove cookie values from the default payload, filter sensitive cookies, or protect the SDK-to-CLI channel with mutual authentication. For [PER-8895], make reset state thread-local, including the fallback behavior, without clearing another thread's session. For [PER-8907], remove the workflow-dispatch branch override or resolve it only to a vetted immutable SHA in a protected workflow.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant