Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Sanitize header and footer user input #125

Merged
merged 1 commit into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion kibana-reports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
"@elastic/elasticsearch": "^7.8.0",
"@elastic/eui": "^26.0.0",
"@nteract/markdown": "^4.5.1",
"@types/dompurify": "^2.0.4",
"@types/jsdom": "^16.2.4",
"babel-polyfill": "^6.26.0",
"cron-validator": "^1.1.1",
"dompurify": "^2.1.1",
"elastic-builder": "^2.7.1",
"jquery": "^3.5.0",
"jsdom": "^16.4.0",
"json-2-csv": "^3.7.6",
"moment": "link:../../packages/moment",
"puppeteer": "^5.3.1",
Expand Down Expand Up @@ -60,12 +64,12 @@
"@testing-library/react": "^10.2.1",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.13",
"@types/puppeteer": "^3.0.2",
"@types/reach__router": "^1.3.5",
"@types/react": "^16.9.36",
"@types/react-dom": "^16.9.8",
"@types/react-test-renderer": "^16.9.2",
"@types/set-interval-async": "^1.0.0",
"@types/puppeteer": "^3.0.2",
"@types/showdown": "^1.9.3",
"babel-eslint": "^10.0.1",
"babel-jest": "^26.0.1",
Expand Down
9 changes: 7 additions & 2 deletions kibana-reports/server/routes/utils/reportHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/

import puppeteer from 'puppeteer';
import createDOMPurify from 'dompurify';
import { JSDOM } from 'jsdom';
import {
FORMAT,
REPORT_TYPE,
Expand All @@ -36,6 +38,9 @@ import { createSavedSearchReport } from './savedSearchReportHelper';
import { ReportSchemaType } from '../../model';
import { CreateReportResultType } from './types';

const window = new JSDOM('').window;
const DOMPurify = createDOMPurify(window);

export const createVisualReport = async (
reportParams: any,
queryUrl: string,
Expand All @@ -50,8 +55,8 @@ export const createVisualReport = async (
const reportFormat = coreParams.report_format;

// TODO: polish default header, maybe add a logo, depends on UX design
const header = coreParams.header || DEFAULT_REPORT_HEADER;
const footer = coreParams.footer || DEFAULT_REPORT_FOOTER;
const header = coreParams.header ? DOMPurify.sanitize(coreParams.header) : DEFAULT_REPORT_HEADER;
const footer = coreParams.footer ? DOMPurify.sanitize(coreParams.footer) : DEFAULT_REPORT_FOOTER;
// set up puppeteer
const browser = await puppeteer.launch({
headless: true,
Expand Down
38 changes: 37 additions & 1 deletion kibana-reports/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,13 @@
resolved "https://registry.yarnpkg.com/@types/dom4/-/dom4-2.0.1.tgz#506d5781b9bcab81bd9a878b198aec7dee2a6033"
integrity sha512-kSkVAvWmMZiCYtvqjqQEwOmvKwcH+V4uiv3qPQ8pAh1Xl39xggGEo8gHUqV4waYGHezdFw0rKBR8Jt0CrQSDZA==

"@types/dompurify@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@types/dompurify/-/dompurify-2.0.4.tgz#25fce15f1f4b1bc0df0ad957040cf226416ac2d7"
integrity sha512-y6K7NyXTQvjr8hJNsAFAD8yshCsIJ0d+OYEFzULuIqWyWOKL2hRru1I+rorI5U0K4SLAROTNuSUFXPDTu278YA==
dependencies:
"@types/trusted-types" "*"

"@types/enzyme@^3.1.13":
version "3.10.5"
resolved "https://registry.yarnpkg.com/@types/enzyme/-/enzyme-3.10.5.tgz#fe7eeba3550369eed20e7fb565bfb74eec44f1f0"
Expand Down Expand Up @@ -1627,6 +1634,15 @@
jest-diff "^25.2.1"
pretty-format "^25.2.1"

"@types/jsdom@^16.2.4":
version "16.2.4"
resolved "https://registry.yarnpkg.com/@types/jsdom/-/jsdom-16.2.4.tgz#527ca99943e00561ca4056b1904fd5f4facebc3b"
integrity sha512-RssgLa5ptjVKRkHho/Ex0+DJWkVsYuV8oh2PSG3gKxFp8n/VNyB7kOrZGQkk2zgPlcBkIKOItUc/T5BXit9uhg==
dependencies:
"@types/node" "*"
"@types/parse5" "*"
"@types/tough-cookie" "*"

"@types/json-schema@^7.0.3":
version "7.0.6"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
Expand Down Expand Up @@ -1667,6 +1683,11 @@
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==

"@types/parse5@*":
version "5.0.3"
resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-5.0.3.tgz#e7b5aebbac150f8b5fdd4a46e7f0bd8e65e19109"
integrity sha512-kUNnecmtkunAoQ3CnjmMkzNU/gtxG8guhi+Fk2U/kOpIKjIMKnXGp4IJCgQJrXSgMsWYimYG4TGjz/UzbGEBTw==

"@types/prettier@^2.0.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.1.0.tgz#5f96562c1075ee715a5b138f0b7f591c1f40f6b8"
Expand Down Expand Up @@ -1758,6 +1779,16 @@
dependencies:
"@types/jest" "*"

"@types/tough-cookie@*":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.0.tgz#fef1904e4668b6e5ecee60c52cc6a078ffa6697d"
integrity sha512-I99sngh224D0M7XgW1s120zxCt3VYQ3IQsuw3P3jbq5GG4yc79+ZjyKznyOGIQrflfylLgcfekeZW/vk0yng6A==

"@types/trusted-types@*":
version "1.0.6"
resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-1.0.6.tgz#569b8a08121d3203398290d602d84d73c8dcf5da"
integrity sha512-230RC8sFeHoT6sSUlRO6a8cAnclO06eeiq1QDfiv2FGCLWFvvERWgwIQD4FWqD9A69BN7Lzee4OXwoMVnnsWDw==

"@types/yargs-parser@*":
version "15.0.0"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-15.0.0.tgz#cb3f9f741869e20cce330ffbeb9271590483882d"
Expand Down Expand Up @@ -3620,6 +3651,11 @@ domhandler@^3.0, domhandler@^3.0.0:
dependencies:
domelementtype "^2.0.1"

dompurify@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.1.1.tgz#b5aa988676b093a9c836d8b855680a8598af25fe"
integrity sha512-NijiNVkS/OL8mdQL1hUbCD6uty/cgFpmNiuFxrmJ5YPH2cXrPKIewoixoji56rbZ6XBPmtM8GA8/sf9unlSuwg==

domutils@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/domutils/-/domutils-2.2.0.tgz#f3ce1610af5c30280bde1b71f84b018b958f32cf"
Expand Down Expand Up @@ -5927,7 +5963,7 @@ jsbn@~0.1.0:
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
integrity sha1-peZUwuWi3rXyAdls77yoDA7y9RM=

jsdom@^16.2.2:
jsdom@^16.2.2, jsdom@^16.4.0:
version "16.4.0"
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-16.4.0.tgz#36005bde2d136f73eee1a830c6d45e55408edddb"
integrity sha512-lYMm3wYdgPhrl7pDcRmvzPhhrGVBeVhPIqeHjzeiHN3DFmD1RBpbExbi8vU7BJdH8VAZYovR8DMt0PNNDM7k8w==
Expand Down