import * as React from 'react'; import * as RadixDirection from '@radix-ui/react-direction'; import { createTheme, Theme, WebTheme, sanitizeNamespaceImport, } from '@aws-amplify/ui'; import { AmplifyContext } from './AmplifyContext'; // Radix packages don't support ESM in Node, in some scenarios(e.g. SSR) // We have to use namespace import and sanitize it to ensure the interoperablity between ESM and CJS const { DirectionProvider } = sanitizeNamespaceImport(RadixDirection); export type ColorMode = 'system' | 'light' | 'dark'; export type Direction = 'ltr' | 'rtl'; interface ThemeProviderProps { children: React.ReactNode; /** * Changes the color mode applied to the theme */ colorMode?: ColorMode; /** * Controls the language direction in the app * @default: 'ltr' */ direction?: Direction; /** * Provide a server generated nonce which matches your CSP `style-src` rule. * This will be attached to the generated tag and add a The answer depends on whether the code is rendered on the client or server side. Client side - To prevent XSS inside of the tag, it will still be interpreted as CSS text by the browser. - Therefore, there is not an XSS vulnerability on the client side. Server side - When React code is rendered on the server side (e.g., NextJS), the code is sent to the browser as HTML text. - Therefore, it *IS* possible to insert a closing tag and escape the CSS context, which opens an XSS vulnerability. Q: How are we mitigating the potential attack vector? A: To fix this potential attack vector on the server side, we need to filter out any closing tags, as this the only way to escape from the context of the browser interpreting the text as CSS. We also need to catch cases where there is any kind of whitespace character , such as tabs, carriage returns, etc: Therefore, by only rendering CSS text which does not include a closing '' tag, we ensure that the browser will correctly interpret all the text as CSS. */} {typeof theme === 'undefined' || /<\/style/i.test(cssText) ? null : (