Tengo un escenario en el que se usa un servicio (leído como fetchDomainForUser() en el fragmento de código a continuación) para crear una URL que se usa en iframe.
La aplicación permite dominios agregando encabezados CSP - frame-src pero hay muchos dominios que son posibles. No es posible incluir en la lista blanca ningún dominio.
¿Es posible cargar contenido '.aspx' fuera de iFrame y luego agregar contenido a iframe?
const [contentWindow, setContentWindow] = React.useState<Window | null>(null); const iFrameUrl = `${fetchDomainForUser()}/solution.aspx`; // fetchDomainForUser() provides domain dynamically React.useEffect(() => { if (contentWindow) { (async (): Promise<void> => { const token = fetchToken(); const form = contentWindow.document.createElement('form'); form.setAttribute('action', iframeUrl); form.setAttribute('method', 'POST'); const accessToken = contentWindow.document.createElement('input'); accessToken.setAttribute('type', 'hidden'); accessToken.setAttribute('name', 'access_token'); accessToken.setAttribute('value', token || ''); form.appendChild(accessToken); contentWindow.document.body.appendChild(form); form.submit(); })().catch(() => { }); } }, [contentWindow, iframeUrl]); const onIFrameRef = React.useCallback((iframeElement: HTMLIFrameElement | null) => { setContentWindow((iframeElement && iframeElement.contentWindow) || null); }, []); return <iframe width={size.width} height={size.height} style={iframeStyle} ref={onIFrameRef} />;