fix(outlook): add Trusted Types policy and extend auth timeout#65
fix(outlook): add Trusted Types policy and extend auth timeout#65conceptblenders wants to merge 2 commits intoopentabs-dev:mainfrom
Conversation
Outlook on cloud.microsoft enforces a Trusted Types CSP policy that causes
zod's allowsEval probe (new Function("")) to log a console violation.
Creating a 'default' Trusted Types policy before any zod code runs lets
the probe complete silently via its existing try/catch.
Also extends waitForAuth timeout from 5000ms to 30000ms. When Outlook
redirects through an OAuth flow (#code= URL fragment), MSAL tokens are
not yet in localStorage when the adapter first initializes. The previous
5s window was too short for the OAuth handshake to complete on slower
connections or enterprise SSO flows.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdded a runtime Trusted Types policy creation in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@plugins/outlook/src/index.ts`:
- Around line 7-10: Replace the unsafe identity createScript policy on the
Trusted Types 'default' policy with a narrow validator: in the block that
defines tt?.createPolicy?.('default', { createScript: ... }) (see the tt
variable and createPolicy usage in plugins/outlook/src/index.ts), change
createScript from returning the input string unconditionally to only accepting
the specific probe string used by Zod/allowsEval (empty string "") and otherwise
throw or reject (so non-empty strings cannot be converted to TrustedScript);
keep the try/catch behavior for unsupported browsers or existing policies.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 72dade4f-f86a-4a47-a77a-76d47b413a68
📒 Files selected for processing (2)
plugins/outlook/src/index.tsplugins/outlook/src/outlook-api.ts
Per CodeRabbit review: the identity createScript function on the default
Trusted Types policy was too permissive, allowing any string to become
TrustedScript. Restrict it to only accept the empty string ("") that
zod's allowsEval probe passes to new Function(), and throw for all other
inputs to preserve Trusted Types protections.
Also check tt.defaultPolicy before creating to avoid duplicate creation.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Outlook on cloud.microsoft enforces a Trusted Types CSP policy that causes zod's allowsEval probe (new Function("")) to log a console violation. Creating a 'default' Trusted Types policy before any zod code runs lets the probe complete silently via its existing try/catch.
Also extends waitForAuth timeout from 5000ms to 30000ms. When Outlook redirects through an OAuth flow (#code= URL fragment), MSAL tokens are not yet in localStorage when the adapter first initializes. The previous 5s window was too short for the OAuth handshake to complete on slower connections or enterprise SSO flows.
Fixes two issues reported in [issue #] affecting Outlook on
cloud.microsoft:Changes
1. Trusted Types policy (
index.ts)Outlook enforces a Trusted Types CSP. Zod's
allowsEvalprobe callsnew Function("")which triggers a console violation. Creating adefaultTrusted Types policy before any zod code runs lets the probe complete
silently via its existing try/catch.
2. Extended auth timeout (
outlook-api.ts)waitForAuthtimeout increased from 5000ms → 30000ms.When Outlook loads via an OAuth redirect (
#code=URL fragment), MSAL tokensare not yet in localStorage when the adapter first initializes. The 5s window
was too short for the OAuth handshake + token storage to complete, causing
isReady()to return false permanently.Test environment
https://outlook.cloud.microsoft/mail/Summary by CodeRabbit
New Features
Bug Fixes