feat(security): add sandboxed mfe container and dynamic csp generator#627
Open
Dopezapha wants to merge 2 commits into
Open
feat(security): add sandboxed mfe container and dynamic csp generator#627Dopezapha wants to merge 2 commits into
Dopezapha wants to merge 2 commits into
Conversation
|
@Dopezapha Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #600
Closes #576
PR Description
This pull request implements two security-focused frontend features for SoroTask: a sandboxed Micro-Frontend (MFE) container and a dynamic Content Security Policy (CSP) header generator. Both features have been designed to enforce strict security boundaries, handle edge cases resiliently, provide observability hooks, and satisfy 100% of their respective acceptance criteria.
Issue #600: [Frontend] Develop Secure Micro-Frontend (MFE) Container Application
Implementation & Fixes Details
errorevents on HTML<iframe>elements do not fire reliably for cross-origin network errors, 404s, or remote application crashes, a custom handshake design was implemented. The container initializes a configurable timer (initTimeoutMs, default 5 seconds) on mount. The child micro-frontend must notify the parent container by posting aMFE_READYorHEARTBEATmessage within this time frame. Once received, the timer is cleared, and the loading spinner is unmounted. If the timer runs out before receiving a valid heartbeat, the container unmounts the iframe and renders the fallback UI.MFE_ERRORmessage to indicate an internal application failure. Upon receipt of this message, the container immediately unmounts the iframe and presents the fallback UI.messageevent is filtered against a whitelisted array of origins. Messages from unauthorized origins are logged as warnings and rejected immediately.allow-scripts allow-same-origin allow-forms allow-popupsto prevent top-level navigation, parent hijacking, or other elevated access.no-referrerto prevent passing authentication tokens or sensitive path metadata in outbound request headers.Acceptance Criteria Verification
frontend/docs/mfe-container.md.Issue #576: [Frontend] Implement Content Security Policy (CSP) Dynamic Generator
Implementation & Fixes Details
default-src 'self',object-src 'none',frame-ancestors 'none', andupgrade-insecure-requests).'nonce-<token>') to allow trust-anchored inline scripts when usingstrict-dynamic.process.env.NODE_ENVis set todevelopment(or reads a passed override flag) to append'unsafe-eval'and'unsafe-inline', which are required for Vite/Webpack hot module reloading.report-uridirective to the CSP header, allowing browsers to post JSON violation reports to the specified endpoint when a policy breach occurs.Acceptance Criteria Verification
frontend/docs/csp-generator.md.Changes Made
frontend/components/mfe-container.tsxcontaining the sandboxed iframe container and postMessage/heartbeat validation logic.frontend/components/__tests__/mfe-container.test.tsxverifying sandbox attribute assignment, loading indicators, trusted message handling, untrusted message rejection, timeout fallback, and message-driven error handling.frontend/lib/csp-generator.tswith options for script nonces, dev mode bypasses, custom directives, and report-uri violation tracking.frontend/lib/__tests__/csp-generator.test.tstesting base generation, nonce injection, development flags, custom directive merging, and report-uri construction.frontend/docs/mfe-container.mdandfrontend/docs/csp-generator.mdto house the architectural and security documentation for each issue.frontend/jest.config.jsto include thecomponentsandlibdirectories in Jest's matching patterns so that the new test suites run.Testing