react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

Getting CSP error

Open parithibang opened this issue 1 year ago • 7 comments

Describe the bug I am trying to consume the package and while rendering I am getting refused to connect due to CSP. Suppose if I add the following lines then it is allowing me to render the pdf.

csp["connect-src"] += " data:";
csp["script-src"] += " 'unsafe-eval'";
csp["frame-src"] += " blob:";

But looks like it is not recommended to add all these CSPs to my codebase.

To Reproduce Steps to reproduce the behavior including code snippet (if applies):

My Code:

import React, { useEffect, useState } from "react";
import { Document, Page, PDFViewer, StyleSheet, View, Text } from "@react-pdf/renderer";

const ReactPdfViewer: React.FC = () => {
  const stylesPdf = StyleSheet.create({
    page: {
      flexDirection: "row",
      backgroundColor: "#E4E4E4"
    },
    section: {
      margin: 10,
      padding: 10,
      flexGrow: 1
    }
  });

  // Create Document Component
  const MyDocument = () => (
    <Document>
      <Page size="A4" style={stylesPdf.page}>
        <View style={stylesPdf.section}>
          <Text>Section #1</Text>
        </View>
        <View style={stylesPdf.section}>
          <Text>Section #2</Text>
        </View>
      </Page>
    </Document>
  );

  return (
    <>
      <PDFViewer>
        <MyDocument />
      </PDFViewer>
    </>
  );
};

export default ReactPdfViewer;

Screenshots Screenshot 2024-02-05 at 1 14 13 PM

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: chrome, safari
  • React-pdf version: @react-pdf/renderer:3.3.4

parithibang avatar Feb 05 '24 07:02 parithibang

I'm having the same issue since updating to version 3.3.8, this wasn't the case for version 3.1.14.

rconjaerts avatar Feb 12 '24 13:02 rconjaerts

I also have the same error on 3.38 :(

askasp avatar Feb 27 '24 09:02 askasp

I am experiencing this in version 3.1.16. You can observe in the playground that there is a data:application/octet-stream;base64,... request made with each change.

This appears to have some references to Yoga, e.g.

Child already has a owner, it must be removed first.�Cannot set measure function: Nodes with measure functions cannot have children.�Cannot add child: Nodes with measure functions cannot have children.�

edwindwalker avatar Mar 27 '24 13:03 edwindwalker

The same on my side

Muhamedkaric avatar Mar 29 '24 10:03 Muhamedkaric

This issue is valid for version 3.4.2 as well

lorena-caia avatar Apr 19 '24 13:04 lorena-caia

Is there any update on the above?

mariyana-ivanova avatar Jun 20 '24 14:06 mariyana-ivanova

👋 is it going to be fixed in the coming releases?

aandriyenko avatar Jul 06 '24 04:07 aandriyenko