-
Notifications
You must be signed in to change notification settings - Fork 0
feat: support *.optimizelocation.com for useMessage #965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
commit: |
WalkthroughThe changes add a new utility function Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
packages/visual-editor/src/internal/hooks/useMessage.ts (1)
219-219: ParametertargetOriginsis now ignored.The
targetOriginsparameter (line 201) is no longer used after this change. This breaks the contract ofuseListenAndRespondMessageand its public callers, which still accept and pass this parameter but now silently ignore it.If the intent is to always validate against
TARGET_ORIGINS+*.optimizelocation.com, thetargetOriginsparameter should be removed from:
- Line 201:
useListenAndRespondMessagesignature- Line 94:
useSendMessageToIFramesignature- Line 129:
useSendMessageToParentsignature- Line 164:
useReceiveMessagesignatureThis would be a breaking API change but makes the behavior explicit.
Note: This relates to the past review comment "TARGET_ORIGINS is a const so just use that instead of passing it in" — the parameter should be removed to complete the refactoring.
🧹 Nitpick comments (1)
packages/visual-editor/src/internal/hooks/useMessage.test.ts (1)
1-80: Comprehensive test coverage with room for minor enhancements.The test suite thoroughly covers the core functionality of
isOriginAllowed:
- All seven TARGET_ORIGINS entries
- HTTP and HTTPS protocols for
*.optimizelocation.com- Various subdomains and the root domain
- Invalid URLs and edge cases
- Combined exact and pattern-based matching
Optional: Additional edge cases to strengthen test coverage
Consider adding tests for:
- Multi-level subdomains (explicitly):
+ it("should return true for multi-level subdomains", () => { + expect(isOriginAllowed("https://a.b.c.optimizelocation.com")).toBe(true); + });
- Case variations (verify URL constructor normalization):
+ it("should handle case-insensitive hostnames", () => { + expect(isOriginAllowed("https://XYZ.OptimizeLocation.COM")).toBe(true); + });
- Origins with explicit ports:
+ it("should handle origins with ports", () => { + expect(isOriginAllowed("https://xyz.optimizelocation.com:8080")).toBe(true); + expect(isOriginAllowed("http://localhost:3000")).toBe(false); + });
- Domain confusion attacks:
+ it("should reject similar but invalid domains", () => { + expect(isOriginAllowed("https://optimizelocation.com.evil.com")).toBe(false); + expect(isOriginAllowed("https://fakeoptimizelocation.com")).toBe(false); + });These additions would provide defense-in-depth assurance but are not critical given the current implementation.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/visual-editor/src/internal/hooks/useMessage.test.tspackages/visual-editor/src/internal/hooks/useMessage.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/visual-editor/src/internal/hooks/useMessage.test.ts (1)
packages/visual-editor/src/internal/hooks/useMessage.ts (1)
isOriginAllowed(47-67)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: call_unit_test / unit_tests (22.x)
- GitHub Check: call_unit_test / unit_tests (24.x)
- GitHub Check: call_unit_test / unit_tests (20.x)
- GitHub Check: create-dev-release
- GitHub Check: semgrep/ci
🔇 Additional comments (1)
packages/visual-editor/src/internal/hooks/useMessage.ts (1)
231-231: Dependency array is correct for current implementation.Removing
targetOriginsfrom the dependency array is correct since it's no longer referenced inonWatchEventHandler. However, this is part of the incomplete refactoring noted above—iftargetOriginswere properly removed from the function signature, this would be fully consistent.
Added unit tests, but unable to manually test as optimizelocation domains are only configured for production. Will need to smoke test this change along with the change to YSS to ensure nothing breaks in non-prod envs, and then test with an optimizelocation url in production.