← Back to Pull requests

Managed view hierarchy: convert secure rectangles into render pixels before the overlap test #294

Closed
unknown closed this pull request without merging on Nov 24, 2026 14:33 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 16:25 UTC
Author

Fixes #291

What changed


The managed view hierarchy compared node boxes in Unity render pixels with secure rectangles that the registry holds in native pixels. With Resolution Scaling, Screen.SetResolution below the display size, a surface offset (status bar, cutout) or an iOS render scale that differs from the screen scale, a node under a secure rectangle could keep options.name and options.components.

  • SecureRectSpace.NativeToRender (new): the exact inverse of TryToNative (remove the surface offset, scale by screen size over surface size, round outwards, clamp in double). ManagedViewHierarchy.CollectSecureRects runs it on every slice through Bugsee.ConvertSecureRectsToRender, so each slice tests nodes against rectangles in its own render space (the union over slices stays).

  • Fail closed: a surface that was never read, a view caught mid-rotation, or an invalid view makes every rectangle cover everything (SecureRectSpace.CoverScreen); nodes without bounds were already treated as covered.

  • SecureRectScreenSync.CurrentView gives the view quietly (no warning from inside a native request) and leaves the state change for the next Add/Tick to warn about.

  • The wrong "Unity screen pixels" comments (ManagedViewSnapshot, ManagedViewTreeJson.Write) are corrected.

  • CHANGELOG: ## [Unreleased] / ### Fixed bullet (main had no unreleased section).
  • Verification


  • Unit tests (ManagedViewSecureSpaceTests, SecureRectSpaceTests) run the real chain SecureRectScreenOwners -> SecureRectRegistry -> NativeToRender -> ManagedViewTreeJson: native resolution (unchanged), Resolution Scaling 0.5, SetResolution 720x1280 on 1080x1920, surface offset, scale plus offset, iOS scale 2 and 3, iOS render scale differing from the screen scale, manual native rectangles, partly and fully outside, no rectangles, no bounds, huge rectangles, the fail-closed paths. Every scaled/offset case also asserts the pre-fix path (unconverted rectangles) leaks the name, which is the "fails before the fix" proof.

  • dotnet test WrapperPolicy: 2523 passed. compile-check.sh: 11/11 ok.

  • Device (HONOR WOD-LX1, Android 14, IL2CPP dev build, staging token), new sample scenario vhsecurescale (secure rectangle exactly over a named uGUI card, managed view hierarchy captured at native 720x1612 and after Screen.SetResolution to 360x806, secured-node counts from ManagedViewDiagnostics; the scene's other objects are off so counts are stable):

  • - before (origin/main runtime): native secured=4, half secured=1 -> FAIL (the covered card and its siblings kept their names)
    - after (this PR): native secured=4, half secured=4 -> PASS
    The check reads the wrapper's secured-node count, not the JSON name itself; the unit tests assert the names. Final sample (also asserts a named clear corner node stays named, so a PASS cannot come from covering everything): after, native secured=4 of 6 nodes, half secured=4 of 6 -> PASS, failures=0.
  • Five fresh Opus review passes (plus claude[bot] and CodeRabbit rounds); all valid findings fixed.
  • Known gaps


  • iOS: modelled in unit tests only (points x scale surface), no device run.

  • AddSecureRectangle rectangles after a surface that turns unreadable once it was read use the last good surface (same as screen-space ones).

  • No test of the Unity-bound glue Bugsee.ConvertSecureRectsToRender itself (its parts are tested).

  • The node bounds written to the report are still render pixels divided by the iOS scale; out of scope here.
  • Docs that become obsolete (docs repo, not edited here)


  • docs/sdk/unity/view-hierarchy.mdx and privacy/video.mdx, section "Rectangles and the Unity scene tree": the sentences stating that the managed view hierarchy compares node boxes in render pixels with rectangles in native pixels, and that under Resolution Scaling, Screen.SetResolution, a surface offset or a differing iOS scale a node under a rectangle can keep its name and components, no longer hold.
  • 🤖 Generated with Claude Code

    https://claude.ai/code/session_01WeiJxQSiPP4vp79ZPpBsqf

    Diff: 514 lines (+385 / -129) across 6 files Reviewer: krassx Review duration: 1328m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 514 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.374
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #294"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.7% (MEDIUM) · Higher = larger blast radius
    47.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.8% · Safe to merge
    18.8%