Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reporting network policy violation should not cause unhandled promise rejection #71481

Closed
legrego opened this issue Jul 13, 2020 · 7 comments · Fixed by #71989 or #75105
Closed

Reporting network policy violation should not cause unhandled promise rejection #71481

legrego opened this issue Jul 13, 2020 · 7 comments · Fixed by #71989 or #75105
Labels
chore Feature:Reporting:Framework Reporting issues pertaining to the overall framework needs-team Issues missing a team label

Comments

@legrego
Copy link
Member

legrego commented Jul 13, 2020

This error currently causes an unhandled promise rejection, which crashes Kibana when running in dev mode. This should be addressed so that the error is caught and handled correctly:

Steps to reproduce:

  1. Constrain the network policy. Here is an example policy which restricts access to via.placeholder.com:
xpack.reporting.capture.networkPolicy.rules: [
   { allow: true, protocol: 'http:' },
   { allow: false, host: via.placeholder.com },
   { allow: true, protocol: 'https:' },
   { allow: false },
]
  1. Create a Canvas workpad (this is just easy to embed an image), which embeds an image to via.placeholder.com:
image 
  dataurl="https://via.placeholder.com/728x90.png?text=test+external+image" mode="contain"
| render
  1. Generate PDF Report of this workpad via the "Share" button:
    image

The report will correctly fail, due to the network policy violation. However, when running in dev mode, this causes the Kibana server to crash, because the error thrown by the code above is not handled by the calling code.

I would expect this error to be caught and logged, rather than being uncaught and relying on the Kibana runtime to handle this.

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-reporting-services (Team:Reporting Services)

@tsullivan
Copy link
Member

Hi @legrego what are the repro steps here, and what would you say is the expected result of the scenario that causes this?

@legrego
Copy link
Member Author

legrego commented Jul 14, 2020

@tsullivan sorry for the vague report, I updated the issue description with reproduction steps. My expectation is that this error would be caught and logged somewhere in the promise chain, instead of getting raised as an uncaught promise rejection

@tsullivan
Copy link
Member

If we can show the error message in the screenshot itself, or as a warning message on the job we'll do that. Generally when anything causes the screenshot to fail, it makes the underlying issue hard to troubleshoot.

It definitely should not cause the server to crash :)

@tsullivan
Copy link
Member

I think I have a fix with #71481, but I'm not sure the best way to test the fix. This will probably need a functional test that has that Canvas expression in a saved worksheet in a a test data archive.

@tsullivan
Copy link
Member

Puppeteer debug logs:

  log   [11:07:17.109] [error][execute][kcp3vgmn0p4c4e467f60efcf][plugins][printable_pdf][reporting] Got bad URL: "https://via.placeholder.com/728x90.png?text=test+external+image", closing browser.
  puppeteer:protocol SEND ► {"sessionId":"F3452C4B0D753B62F61B5A01579F234B","method":"Fetch.failRequest","params":{"errorReason":"Aborted","requestId":"interception-job-121.0"},"id":148} +2ms
  puppeteer:protocol ◀ RECV {"method":"Network.requestWillBeSent","params":{"requestId":"1000032682.162","loaderId":"5BED4B4D556FE57FA71196CD0BC272B5","documentURL":"http://localhost:5601/app/canvas","request":{"url":"https://via.placeholder.com/728x90.png?text=test+external+image","method":"GET","headers":{"Sec-Fetch-Mode":"no-cors","Referer":"http://localhost:5601/app/canvas","User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/77.0.3844.0 Safari/537.36"},"mixedContentType":"none","initialPriority":"Low","referrerPolicy":"no-referrer-when-downgrade"},"timestamp":19654.384208,"wallTime":1594922837.108165,"initiator":{"type":"other"},"type":"Image","frameId":"1CB32F1CC1E82C55B3786DAE1B0AE196","hasUserGesture":true},"sessionId":"F3452C4B0D753B62F61B5A01579F234B"} +0ms
  puppeteer:protocol ◀ RECV {"method":"Network.resourceChangedPriority","params":{"requestId":"1000032682.162","newPriority":"High","timestamp":19654.384667},"sessionId":"F3452C4B0D753B62F61B5A01579F234B"} +0ms
  puppeteer:protocol ◀ RECV {"id":147,"result":{"result":{"type":"boolean","value":false}},"sessionId":"F3452C4B0D753B62F61B5A01579F234B"} +0ms
  puppeteer:protocol SEND ► {"sessionId":"F3452C4B0D753B62F61B5A01579F234B","method":"DOM.describeNode","params":{"objectId":"{\"injectedScriptId\":4,\"id\":2}"},"id":149} +1ms
  puppeteer:protocol ◀ RECV {"id":148,"result":{},"sessionId":"F3452C4B0D753B62F61B5A01579F234B"} +0ms
  puppeteer:protocol SEND ► {"method":"Browser.close","params":{},"id":150} +1ms
Unhandled Promise rejection detected:

Error: Received disallowed outgoing URL: "https://via.placeholder.com/728x90.png?text=test+external+image", exiting
    at CDPSession.client.on (/home/tsullivan/elastic/kibana/x-pack/plugins/reporting/server/browsers/chromium/driver/chromium_driver.ts:229:15)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Terminating process...
  puppeteer:protocol SEND ► {"method":"Browser.close","params":{},"id":151} +2s
  puppeteer:error Error: write EPIPE
  puppeteer:error     at afterWriteDispatched (internal/stream_base_commons.js:78:25)
  puppeteer:error     at writeGeneric (internal/stream_base_commons.js:73:3)
  puppeteer:error     at Socket._writeGeneric (net.js:714:5)
  puppeteer:error     at Socket._write (net.js:726:8)
  puppeteer:error     at doWrite (_stream_writable.js:415:12)
  puppeteer:error     at writeOrBuffer (_stream_writable.js:399:5)
  puppeteer:error     at Socket.Writable.write (_stream_writable.js:299:11)
  puppeteer:error     at PipeTransport.send (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/PipeTransport.js:46:21)
  puppeteer:error     at Connection._rawSend (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/Connection.js:86:21)
  puppeteer:error     at Connection.send (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/Connection.js:72:21)
  puppeteer:error     at gracefullyCloseChrome (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/Launcher.js:201:20)
  puppeteer:error     at Browser.close (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/Browser.js:255:31)
  puppeteer:error     at Browser.close (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/helper.js:112:23)
  puppeteer:error     at Object.kill (/home/tsullivan/elastic/kibana/x-pack/plugins/reporting/server/browsers/chromium/driver_factory/index.ts:125:25)
  puppeteer:error     at TapSubscriber.signal [as _tapNext] (/home/tsullivan/elastic/kibana/x-pack/plugins/reporting/server/browsers/safe_child_process.ts:46:25)
  puppeteer:error     at TapSubscriber._next (/home/tsullivan/elastic/kibana/node_modules/rxjs/src/internal/operators/tap.ts:120:21) +0ms
  puppeteer:error Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
  puppeteer:error     at doWrite (_stream_writable.js:411:19)
  puppeteer:error     at writeOrBuffer (_stream_writable.js:399:5)
  puppeteer:error     at Socket.Writable.write (_stream_writable.js:299:11)
  puppeteer:error     at PipeTransport.send (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/PipeTransport.js:47:21)
  puppeteer:error     at Connection._rawSend (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/Connection.js:86:21)
  puppeteer:error     at Connection.send (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/Connection.js:72:21)
  puppeteer:error     at gracefullyCloseChrome (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/Launcher.js:201:20)
  puppeteer:error     at Browser.close (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/Browser.js:255:31)
  puppeteer:error     at Browser.close (/home/tsullivan/elastic/kibana/node_modules/puppeteer-core/lib/helper.js:112:23)
  puppeteer:error     at Object.kill (/home/tsullivan/elastic/kibana/x-pack/plugins/reporting/server/browsers/chromium/driver_factory/index.ts:125:25)
  puppeteer:error     at TapSubscriber.signal [as _tapNext] (/home/tsullivan/elastic/kibana/x-pack/plugins/reporting/server/browsers/safe_child_process.ts:46:25)
  puppeteer:error     at TapSubscriber._next (/home/tsullivan/elastic/kibana/node_modules/rxjs/src/internal/operators/tap.ts:120:21)
  puppeteer:error     at TapSubscriber.Subscriber.next (/home/tsullivan/elastic/kibana/node_modules/rxjs/src/internal/Subscriber.ts:99:12)
  puppeteer:error     at MergeMapSubscriber.notifyNext (/home/tsullivan/elastic/kibana/node_modules/rxjs/src/internal/operators/mergeMap.ts:168:22)
  puppeteer:error     at InnerSubscriber._next (/home/tsullivan/elastic/kibana/node_modules/rxjs/src/internal/InnerSubscriber.ts:17:17)
  puppeteer:error     at InnerSubscriber.Subscriber.next (/home/tsullivan/elastic/kibana/node_modules/rxjs/src/internal/Subscriber.ts:99:12) +4ms


@tsullivan
Copy link
Member

A PR went in to address this however, the issue still happens in dev mode due to:

throw getDisallowedOutgoingUrlError(interceptedUrl);

@tsullivan tsullivan reopened this Aug 14, 2020
@sophiec20 sophiec20 added Feature:Reporting:Framework Reporting issues pertaining to the overall framework and removed (Deprecated) Team:Reporting Services labels Aug 21, 2024
@botelastic botelastic bot added the needs-team Issues missing a team label label Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Feature:Reporting:Framework Reporting issues pertaining to the overall framework needs-team Issues missing a team label
Projects
None yet
4 participants