You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "inamdarzaid (via GitHub)" <gi...@apache.org> on 2025/09/04 09:57:23 UTC

[PR] feat(Charts): multi page pdf report [superset]

inamdarzaid opened a new pull request, #35014:
URL: https://github.com/apache/superset/pull/35014

   # Multi-Page PDF Generation Implementation
   
   ## Overview
   
   This implementation adds support for generating multi-page PDFs from table data in Superset reports, replacing screenshot-based PDFs with HTML-to-PDF conversion using WeasyPrint.
   
   ## Changes Made
   
   ### 1. Added WeasyPrint Dependency
   
   **File**: `requirements/base.in`
   - Added `weasyprint>=61.0` as a new dependency for HTML-to-PDF conversion
   
   ### 2. Enhanced PDF Utility Functions
   
   **File**: `superset/utils/pdf.py`
   
   Added new functions for HTML-to-PDF conversion:
   
   - `generate_table_html()`: Converts pandas DataFrame to properly formatted HTML
     - Includes CSS for multi-page layout
     - Adds page headers, footers, and page numbering
     - Ensures table headers repeat on each page
     - Provides professional styling
   
   - `build_pdf_from_html()`: Converts HTML to PDF using WeasyPrint
     - Handles WeasyPrint errors gracefully
     - Returns PDF as bytes
   
   - `build_pdf_from_dataframe()`: Complete workflow for DataFrame to PDF
     - Combines HTML generation and PDF conversion
     - Accepts title and description parameters
   
   ### 3. Modified Report Execution Logic
   
   **File**: `superset/commands/report/execute.py`
   
   Enhanced the `_get_pdf()` method:
   - **Smart Detection**: Checks if the chart is a table type (`table`, `pivot_table`, `pivot_table_v2`)
   - **Full Data Access**: Uses `_get_embedded_data()` to get complete dataset (not just visible data)
   - **Multi-page Support**: Generates PDF from full data using HTML conversion
   - **Graceful Fallback**: Falls back to screenshot-based PDF if data-based generation fails
   
   ## Key Features
   
   ### 1. Complete Data Export
   - Uses `embedded_data` which contains the full dataset from `ChartDataResultFormat.JSON`
   - Not limited to currently visible/paginated data in the UI
   - Includes all rows regardless of frontend pagination
   
   ### 2. Professional Multi-Page Layout
   - **Page Headers**: Repeat table headers on every page
   - **Page Breaks**: Intelligent page breaking to avoid splitting rows
   - **Page Numbers**: Automatic page numbering in footer
   - **Styling**: Professional table formatting with alternating row colors
   
   ### 3. CSS Features for PDF
   ```css
   @page {
       size: A4;
       margin: 2cm 1.5cm;
       @bottom-center {
           content: "Page " counter(page) " of " counter(pages);
       }
   }
   
   /* Table headers repeat on each page */
   .data-table thead {
       display: table-header-group;
   }
   
   /* Prevent row breaks across pages */
   .data-table tbody tr {
       page-break-inside: avoid;
   }
   ```
   
   ### 4. Error Handling
   - Gracefully handles missing WeasyPrint installation
   - Falls back to screenshot-based PDF generation on errors
   - Provides detailed error logging
   
   ## Usage Flow
   
   1. **Report Generation Request**: User requests PDF report for a table chart
   2. **Chart Type Detection**: System checks if chart is table-based
   3. **Data Retrieval**: `_get_embedded_data()` fetches complete dataset as DataFrame
   4. **HTML Generation**: DataFrame converted to HTML with multi-page CSS
   5. **PDF Conversion**: WeasyPrint converts HTML to multi-page PDF
   6. **Fallback**: If any step fails, falls back to screenshot-based PDF
   
   ## Benefits
   
   ### Before (Screenshot-based)
   - ❌ Limited to visible data only
   - ❌ Single page screenshots stitched together
   - ❌ Poor text quality (image-based)
   - ❌ Large file sizes
   - ❌ No searchable text
   
   ### After (HTML-to-PDF)
   - ✅ Complete dataset included
   - ✅ True multi-page layout
   - ✅ High-quality text rendering
   - ✅ Smaller file sizes
   - ✅ Searchable PDF content
   - ✅ Professional page headers/footers
   - ✅ Proper page breaking
   
   ## Installation Requirements
   
   After these changes, you'll need to:
   
   1. **Install WeasyPrint**: Run `pip install weasyprint>=61.0` or use the updated requirements
   2. **System Dependencies**: WeasyPrint may require system-level dependencies (varies by OS)
   
   ## Compatibility
   
   - **Backward Compatible**: Existing screenshot-based PDF generation remains as fallback
   - **Chart Types**: Currently enabled for `table`, `pivot_table`, and `pivot_table_v2` charts
   - **Other Charts**: Non-table charts continue using screenshot-based PDF generation
   
   ## Future Enhancements
   
   Potential improvements:
   - Extend to other chart types with tabular data
   - Add configuration options for PDF styling
   - Support for custom page layouts
   - Chart embedding alongside table data


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #35014:
URL: https://github.com/apache/superset/pull/35014#issuecomment-3254736468

   Superset uses Git pre-commit hooks courtesy of [pre-commit](https://pre-commit.com/). To install run the following:
   ```
   pip3 install -r requirements/development.txt
   pre-commit install
   ```
   A series of checks will now run when you make a git commit.
   
   Alternatively it is possible to run pre-commit by running pre-commit manually:
   ```
   pre-commit run --all-files
   ``` 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2321504807


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   ### HTML escaping disabled in DataFrame rendering <sub>![category Security](https://img.shields.io/badge/Security-e11d48)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The DataFrame's to_html method is called with escape=False when generating PDF content, which could allow HTML injection attacks if the data contains malicious content.
   
   
   ###### Why this matters
   Malicious data in the DataFrame could execute unwanted HTML/JavaScript code in the generated PDF, potentially leading to XSS attacks when the PDF is viewed.
   
   ###### Suggested change ∙ *Feature Preview*
   Change `escape=False` to `escape=True` in the DataFrame to_html call:
   ```python
   df.to_html(na_rep="", index=True, escape=True)
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d339fed7-bf10-40ce-9166-0a3f128a5bdf/upvote) [![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d339fed7-bf10-40ce-9166-0a3f128a5bdf?what_not_true=true)  [![Not in Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d339fed7-bf10-40ce-9166-0a3f128a5bdf?what_out_of_scope=true) [![Not in coding standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d339fed7-bf10-40ce-9166-0a3f128a5bdf?what_not_in_standard=true) [![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d339fed7-bf10-40ce-9166-0a3f128a5bdf)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:418a6187-2e6b-4be0-aa8f-2bd96ed1b80e -->
   
   
   [](418a6187-2e6b-4be0-aa8f-2bd96ed1b80e)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2325965956


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   ```suggestion
                   {df.to_html(na_rep="", index=True, escape=True)}
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on PR #35014:
URL: https://github.com/apache/superset/pull/35014#issuecomment-3259650511

   Thank you for the contribution @inamdarzaid!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #35014:
URL: https://github.com/apache/superset/pull/35014#issuecomment-6281865198

   Thanks @inamdarzaid for putting this together, paginated PDF exports would indeed be valuable, it's been a recurring request. Hoever, since the branch here is conflicting, CI is failing, we haven't heard anything in upward of t months, and the WeasyPrint dependency still needs resolution via dev@ discussion or a SIP, I'm going to close this out for now. Please open a fresh PR if that discussion lands somewhere, or we can reopen this one if you want to rekindle it. Thanks for this and any future contribution. We very much appreciate it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322113395


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Ok, we'll proceed with the escape=True change. Let us know once the PR is updated.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322091930


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Could you help clarify - are you referring to adding HTML sanitization before WeasyPrint processing? We can break down the security changes into specific tasks to discuss. Which aspect would you like to focus on first?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322102089


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   2



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322171980


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Here are the exact steps to make the security fixes:
   
   1. Open superset/reports/notifications/email.py
   2. Go to line 190 (PDF section)
   3. Replace this line:
      df.to_html(na_rep="", index=True, escape=False)
      with:
      df.to_html(na_rep="", index=True, escape=True)
   
   Need me to explain any of these steps?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322122786


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   you need help updating



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322117308


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Yos



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322116928


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Do you need help updating the PR with the escape=True change? Let me know if you have questions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322114528


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Pr



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322170901


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Y



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322124148


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   You need to update 2 sections:
   
   1. In the PDF generation section:
   ```python
   # Around line 190, change:
   df.to_html(na_rep="", index=True, escape=False)
   # to:
   df.to_html(na_rep="", index=True, escape=True)
   ```
   
   2. Add HTML sanitization after that:
   ```python 
   html_table = nh3.clean(df_html, tags=TABLE_TAGS, attributes=ALLOWED_TABLE_ATTRIBUTES)
   ```
   
   Let me know if you need help with this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322085191


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   N



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322104449


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   1



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "sorren205 (via GitHub)" <gi...@apache.org>.
sorren205 commented on PR #35014:
URL: https://github.com/apache/superset/pull/35014#issuecomment-4041268820

   I would really appreciate this big improvement. Sounds very promising. Any updates of the progress?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2325963197


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")

Review Comment:
   The config file has defaults, so there's no need to set them again here. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322002111


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Good reference. The WeasyPrint docs emphasize HTML injection risks even further. Both DataFrame HTML and WeasyPrint HTML parsing need to be secured. We should:
   1. Keep `escape=True` in DataFrame.to_html()
   2. Add additional HTML sanitization before WeasyPrint processing
   3. Consider WeasyPrint's URL fetching settings to prevent local file access



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322088563


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   2



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322112126


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Yos



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322109547


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   escape=True



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322086186


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Could you please clarify your response? We're discussing important security considerations around HTML escaping in WeasyPrint and DataFrame rendering - what specific aspect are you commenting on?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322121340


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Here's how to fix the security issue:
   
   Find this line in the PDF generation section:
   ```python
   df.to_html(na_rep="", index=True, escape=False)
   ```
   
   Change it to:
   ```python
   df.to_html(na_rep="", index=True, escape=True)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322106284


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   N



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #35014:
URL: https://github.com/apache/superset/pull/35014#issuecomment-3252891874

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
   
   <details>
   <summary>
   Bito Usage Guide
   </summary>
   
   **Commands**
         
   Type the following command in the pull request comment and save the comment.
         
   - `/review` - Manually triggers a full AI review.
   
   - `/pause` - Pauses automatic reviews on this pull request.
   - `/resume` - Resumes automatic reviews.
   - `/resolve` - Marks all Bito-posted review comments as resolved.
   - `/abort` - Cancels all in-progress reviews.
   
         
   Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
         
   **Configuration**
   
   This repository uses `Default Agent` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
         
   **Documentation & Help**
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
   
   </details>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #35014:
URL: https://github.com/apache/superset/pull/35014#issuecomment-4747958227

   There's clear demand for paginated PDFs here, but pulling in WeasyPrint as a new core dependency is a big call that needs broader buy-in, and CI is fully red right now. Can you get pre-commit and the test suites green, and maybe raise the dependency question on the dev@ list first for lazy consensus? Let me know if you're not on the dev list and/or need help with that process.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas closed pull request #35014: feat(Charts): multi page pdf report
URL: https://github.com/apache/superset/pull/35014


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322085191


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   N



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2321513044


##########
tests/unit_tests/reports/notifications/email_tests.py:
##########
@@ -98,3 +103,173 @@ def test_email_subject_with_datetime() -> None:
     )._get_subject()
     assert datetime_pattern not in subject
     assert now.strftime(datetime_pattern) in subject
+
+
+@patch('superset.reports.notifications.email.is_feature_enabled')
+@patch('superset.reports.notifications.email.CSS')
+@patch('superset.reports.notifications.email.HTML')
+@patch('superset.reports.notifications.email.app')
+def test_pdf_generation_triggered_and_content(mock_app, mock_html, mock_css, mock_is_feature_enabled):
+    mock_is_feature_enabled.return_value = False # For self._name simplicity
+    mock_app.config.get.side_effect = get_app_config_mock(DEFAULT_PDF_CONFIG)
+
+    mock_pdf_bytes = b"mock_pdf_content"
+    mock_html_instance = MagicMock()
+    mock_html_instance.write_pdf.return_value = mock_pdf_bytes
+    mock_html.return_value = mock_html_instance
+
+    mock_content = MagicMock(spec=NotificationContent)
+    mock_content.name = "Test Report Name"
+    mock_content.description = "Test PDF Description"
+    mock_content.embedded_data = pd.DataFrame({'col1': [10, 20], 'col2': ['X', 'Y']})
+    mock_content.screenshots = None
+    mock_content.csv = None
+    mock_content.pdf = None
+    mock_content.text = None
+    mock_content.report_format = "PDF"
+    mock_content.url = "http://superset.example.com"
+    mock_content.header_data = {}
+
+    notification = EmailNotification(recipient=MagicMock(), content=mock_content)
+    email_content_result = notification._get_content()
+
+    mock_html.assert_called_once()
+    args_html, kwargs_html = mock_html.call_args
+    html_passed_to_weasyprint = kwargs_html.get('string', args_html[0] if args_html else '')
+    assert '<div class="report-description">Test PDF Description</div>' in html_passed_to_weasyprint
+    assert "<td>X</td>" in html_passed_to_weasyprint # Check for df.to_html(..., escape=False)
+    assert ":root" in html_passed_to_weasyprint # Check for CSS variables block
+    assert f'--report-name-var: "{mock_content.name}";' in html_passed_to_weasyprint
+
+    mock_css.assert_called_once()
+    args_css, kwargs_css = mock_css.call_args
+    css_string_passed = kwargs_css.get('string', args_css[0] if args_css else '')
+    assert "@page { size: A4 portrait; margin: 2.5cm 1.5cm 2cm 1.5cm; }" in css_string_passed
+    assert 'body { font-family: sans-serif; }' in css_string_passed
+
+    assert email_content_result.pdf == {f"{mock_content.name}.pdf": mock_pdf_bytes}
+    # Check that html_table is not included in the email body
+    assert "<table" not in email_content_result.body
+    assert mock_content.description not in email_content_result.body # Description should be in PDF
+
+@patch('superset.reports.notifications.email.is_feature_enabled')
+@patch('superset.reports.notifications.email.CSS')
+@patch('superset.reports.notifications.email.HTML')
+@patch('superset.reports.notifications.email.app')
+def test_pdf_headers_footers_enabled(mock_app, mock_html, mock_css, mock_is_feature_enabled):
+    mock_is_feature_enabled.return_value = False
+    config = {**DEFAULT_PDF_CONFIG, "PDF_EXPORT_HEADERS_FOOTERS_ENABLED": True}
+    mock_app.config.get.side_effect = get_app_config_mock(config)
+
+    mock_html_instance = MagicMock()
+    mock_html_instance.write_pdf.return_value = b"pdf"
+    mock_html.return_value = mock_html_instance
+
+    mock_content = MagicMock(spec=NotificationContent, name="My Report", description="Desc", report_format="PDF", embedded_data=pd.DataFrame({'A': [1]}))
+    mock_content.url = "http://superset.example.com"
+    mock_content.header_data = {}
+
+
+    notification = EmailNotification(recipient=MagicMock(), content=mock_content)
+    notification._get_content()
+
+    mock_css.assert_called_once()
+    args_css, _ = mock_css.call_args
+    css_string = args_css[0]
+
+    expected_header_content = config["PDF_EXPORT_HEADER_TEMPLATE"].replace("{report_name}", "My Report")
+    expected_header_content = expected_header_content.replace("{page_number}", "counter(page)")
+    expected_header_content = expected_header_content.replace("{total_pages}", "counter(pages)")
+
+    expected_footer_content = config["PDF_EXPORT_FOOTER_TEMPLATE"].replace("{generation_date}", notification.now.strftime('%Y-%m-%d %H:%M:%S UTC'))
+    expected_footer_content = expected_footer_content.replace("{report_name}", "My Report")
+
+    assert f'@page @top-center {{ content: "{expected_header_content}"; font-size: 9pt; color: #333; }}' in css_string
+    assert f'@page @bottom-center {{ content: "{expected_footer_content}"; font-size: 9pt; color: #333; }}' in css_string
+
+@patch('superset.reports.notifications.email.is_feature_enabled')
+@patch('superset.reports.notifications.email.CSS')
+@patch('superset.reports.notifications.email.HTML')
+@patch('superset.reports.notifications.email.app')
+def test_pdf_headers_footers_disabled(mock_app, mock_html, mock_css, mock_is_feature_enabled):
+    mock_is_feature_enabled.return_value = False
+    config = {**DEFAULT_PDF_CONFIG, "PDF_EXPORT_HEADERS_FOOTERS_ENABLED": False}
+    mock_app.config.get.side_effect = get_app_config_mock(config)
+
+    mock_html_instance = MagicMock()
+    mock_html_instance.write_pdf.return_value = b"pdf"
+    mock_html.return_value = mock_html_instance
+
+    mock_content = MagicMock(spec=NotificationContent, name="My Report", description="Desc", report_format="PDF", embedded_data=pd.DataFrame({'A': [1]}))
+    mock_content.url = "http://superset.example.com"
+    mock_content.header_data = {}
+
+    notification = EmailNotification(recipient=MagicMock(), content=mock_content)
+    notification._get_content()
+
+    mock_css.assert_called_once()
+    args_css, _ = mock_css.call_args
+    css_string = args_css[0]
+    assert '@page @top-center { content: ""; }' in css_string # Check one, assume others are similar
+    assert '@page @bottom-center { content: ""; }' in css_string
+
+
+@patch('superset.reports.notifications.email.is_feature_enabled')
+@patch('superset.reports.notifications.email.CSS')
+@patch('superset.reports.notifications.email.HTML')
+@patch('superset.reports.notifications.email.app')
+def test_pdf_page_size_orientation(mock_app, mock_html, mock_css, mock_is_feature_enabled):
+    mock_is_feature_enabled.return_value = False
+    config = {**DEFAULT_PDF_CONFIG, "PDF_EXPORT_PAGE_SIZE": "Letter", "PDF_EXPORT_ORIENTATION": "landscape"}
+    mock_app.config.get.side_effect = get_app_config_mock(config)
+
+    mock_html_instance = MagicMock()
+    mock_html_instance.write_pdf.return_value = b"pdf"
+    mock_html.return_value = mock_html_instance
+
+    mock_content = MagicMock(spec=NotificationContent, name="My Report", description="Desc", report_format="PDF", embedded_data=pd.DataFrame({'A': [1]}))
+    mock_content.url = "http://superset.example.com"
+    mock_content.header_data = {}
+
+    notification = EmailNotification(recipient=MagicMock(), content=mock_content)
+    notification._get_content()
+
+    mock_css.assert_called_once()
+    args_css, _ = mock_css.call_args
+    css_string = args_css[0]
+    assert "@page { size: Letter landscape; margin: 2.5cm 1.5cm 2cm 1.5cm; }" in css_string
+
+@patch('superset.reports.notifications.email.is_feature_enabled')
+@patch('superset.reports.notifications.email.CSS')
+@patch('superset.reports.notifications.email.HTML')
+@patch('superset.reports.notifications.email.app')
+def test_fallback_to_html_when_not_pdf_format(mock_app, mock_html, mock_css, mock_is_feature_enabled):
+    mock_is_feature_enabled.return_value = False
+    mock_app.config.get.side_effect = get_app_config_mock(DEFAULT_PDF_CONFIG)
+
+    mock_content = MagicMock(spec=NotificationContent)
+    mock_content.name = "HTML Report"
+    mock_content.description = "HTML Description"
+    mock_content.embedded_data = pd.DataFrame({'col1': [1], 'col2': ['A']})
+    mock_content.screenshots = None
+    mock_content.csv = None
+    mock_content.pdf = None
+    mock_content.text = None
+    mock_content.report_format = "PNG" # Not PDF
+    mock_content.url = "http://superset.example.com"
+    mock_content.header_data = {}
+
+
+    notification = EmailNotification(recipient=MagicMock(), content=mock_content)
+    email_content_result = notification._get_content()
+
+    mock_html.assert_not_called()
+    mock_css.assert_not_called()
+
+    assert email_content_result.pdf is None
+    assert "HTML Description" in email_content_result.body
+    assert "<table" in email_content_result.body # HTML table should be in body
+    # Check that pandas escapes HTML by default
+    mock_content.embedded_data = pd.DataFrame({'col1': ['<script>alert(1)</script>']})
+    email_content_result_escaped = notification._get_content()

Review Comment:
   
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Test logic error in HTML escaping validation</b></div>
   <div id="fix">
   
   Test logic error: The test modifies `mock_content.embedded_data` after creating the `EmailNotification` instance but expects the second `_get_content()` call to use the new data. Create a new `EmailNotification` instance with the modified content to properly test HTML escaping.
   </div>
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```suggestion
       # Check that pandas escapes HTML by default
       mock_content.embedded_data = pd.DataFrame({'col1': ['<script>alert(1)</script>']})
       notification_escaped = EmailNotification(recipient=MagicMock(), content=mock_content)
       email_content_result_escaped = notification_escaped._get_content()
   ```
   
   </div>
   </details>
   </div>
   
   
   
   <small><i>Code Review Run <a href=https://github.com/apache/superset/pull/35014#issuecomment-3252891874>#28dabd</a></i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322103234


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   We need more specific input from you to properly address the security concerns. Please clarify exactly what you'd like to discuss about the HTML sanitization requirements.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322107586


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   For clarity - do you agree we should change DataFrame.to_html() to use escape=True for security? A simple yes/no is fine.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322090881


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   2



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "SupersetOdT (via GitHub)" <gi...@apache.org>.
SupersetOdT commented on PR #35014:
URL: https://github.com/apache/superset/pull/35014#issuecomment-3717181477

   Hello, with Playwright and my webdriver window set to a pixel density of "4", PDF quality is really excellent ("2" is a good compromise between quality and speed - file size - resources).
   
   `WEBDRIVER_WINDOW = {
   	"dashboard": (1684, 2384),
   	"slice": (2384, 1684), 
       "pixel_density": 2,
   }`
   
   However, I would be very happy to be able to take advantage of the PDF being divided into A4 or A3 pages because sometimes those who receive the reports have to print them. Currently, when a dashboard is very long, the PDF extends vertically without cutting. It is difficult to print. If this PR also allows to avoid that the graphs are cut in half when they arrive between 2 pages, if this PR also allows to add a numbering, a heading... what more could you ask for ?... 🤩
   
   Can you keep us informed of the progress?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "msyavuz (via GitHub)" <gi...@apache.org>.
msyavuz commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322001043


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   This might be especially important with
   https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#python-library
   
   First warning there and the security part of their docs mentioning this



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322089729


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Could you specify which security point you're referring to with "2"? We discussed multiple aspects:
   - DataFrame HTML escaping
   - WeasyPrint HTML sanitization  
   - WeasyPrint URL fetch settings



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322105897


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Let's focus on the specific security fix needed: Setting `escape=True` for DataFrame HTML generation. Do you have concerns about implementing this change?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322110880


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Great, changing to escape=True will help prevent HTML injection attacks. PR can be updated with this security fix.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "waelrimas566-png (via GitHub)" <gi...@apache.org>.
waelrimas566-png commented on code in PR #35014:
URL: https://github.com/apache/superset/pull/35014#discussion_r2322120024


##########
superset/reports/notifications/email.py:
##########
@@ -132,19 +133,124 @@ def _get_content(self) -> EmailContent:
             attributes=ALLOWED_ATTRIBUTES,
         )
 
-        # Strip malicious HTML from embedded data, allowing only table elements
-        if self._content.embedded_data is not None:
+        pdf_data = None
+        html_table = ""
+
+        # Check if the report format is PDF and embedded data is available
+        # Assuming self._content.report_format exists and holds the report format string
+        if hasattr(self._content, 'report_format') and \
+           self._content.report_format == "PDF" and \
+           self._content.embedded_data is not None:
             df = self._content.embedded_data
-            # pylint: disable=no-member
-            html_table = nh3.clean(
-                df.to_html(na_rep="", index=True, escape=True),
-                # pandas will escape the HTML in cells already, so passing
-                # more allowed tags here will not work
-                tags=TABLE_TAGS,
-                attributes=ALLOWED_TABLE_ATTRIBUTES,
-            )
-        else:
+            report_name_val = self._name # Renamed to avoid clash with CSS variable name
+            generation_date_val = self.now.strftime('%Y-%m-%d %H:%M:%S UTC')
+
+            # Retrieve PDF export configurations
+            pdf_headers_footers_enabled = app.config.get("PDF_EXPORT_HEADERS_FOOTERS_ENABLED", True)
+            pdf_header_template = app.config.get("PDF_EXPORT_HEADER_TEMPLATE", "Report: {report_name} - Page {page_number} of {total_pages}")
+            pdf_footer_template = app.config.get("PDF_EXPORT_FOOTER_TEMPLATE", "Generated: {generation_date}")
+            pdf_page_size = app.config.get("PDF_EXPORT_PAGE_SIZE", "A4")
+            pdf_orientation = app.config.get("PDF_EXPORT_ORIENTATION", "portrait")
+
+            # Prepare header and footer content based on templates and config
+            header_content_str = ""
+            footer_content_str = ""
+
+            if pdf_headers_footers_enabled:
+                # Sanitize report_name_val for CSS content (simple escaping for quotes)
+                css_report_name = report_name_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+                css_generation_date = generation_date_val.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\A")
+
+                # For header: replace {report_name}, keep {page_number} and {total_pages} for CSS counters
+                header_content_str = pdf_header_template.replace("{report_name}", css_report_name)
+                header_content_str = header_content_str.replace("{page_number}", "counter(page)")
+                header_content_str = header_content_str.replace("{total_pages}", "counter(pages)")
+
+                # For footer: replace {generation_date} and {report_name}
+                footer_content_str = pdf_footer_template.replace("{generation_date}", css_generation_date)
+                footer_content_str = footer_content_str.replace("{report_name}", css_report_name)
+
+
+            pdf_html_content = f"""
+            <html>
+            <head>
+                <meta charset="UTF-8">
+                <style>
+                    :root {{
+                        /* Keeping these for potential use in body styles if needed */
+                        --report-name-var: "{report_name_val.replace('"', '&quot;').replace("'", "&apos;")}";
+                        --generation-date-var: "{generation_date_val}";
+                    }}
+                </style>
+            </head>
+            <body>
+                <div class="report-description">{description}</div>
+                <br>
+                {df.to_html(na_rep="", index=True, escape=False)}

Review Comment:
   Yos



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #35014:
URL: https://github.com/apache/superset/pull/35014#issuecomment-3544079816

   Superset uses Git pre-commit hooks courtesy of [pre-commit](https://pre-commit.com/). To install run the following:
   ```
   pip3 install -r requirements/development.txt
   pre-commit install
   ```
   A series of checks will now run when you make a git commit.
   
   Alternatively it is possible to run pre-commit by running pre-commit manually:
   ```
   pre-commit run --all-files
   ``` 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat(Charts): multi page pdf report [superset]

Posted by "inamdarzaid (via GitHub)" <gi...@apache.org>.
inamdarzaid commented on PR #35014:
URL: https://github.com/apache/superset/pull/35014#issuecomment-4756811189

   Thanks for the feedback. I'll first get the branch rebased and CI green. Regarding WeasyPrint, I agree this introduces a significant new dependency. My intent was to demonstrate a path toward true paginated table exports rather than mandate a specific implementation. I'll start a discussion on dev@ to gather feedback on dependency acceptance and possible alternative approaches.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org