OWASP / threat-dragon

An open source threat modeling tool from OWASP
https://owasp.org/www-project-threat-dragon/
Apache License 2.0
933 stars 251 forks source link

Can't print reports #436

Closed dzablo closed 1 year ago

dzablo commented 2 years ago

Describe the bug When I try to "print" the report, the app crash. here is the test JSON file test.json.log

Expected behaviour I should be able to "print" the report.

Environment

To Reproduce

  1. Create a new report
  2. Click the report
  3. Click the print

Any additional context, screenshots, etc here is the error I get in the terminal


(node:234607) [DEP0128] DeprecationWarning: Invalid 'main' field in '/home/adamjablonski/git/tools/threat-dragon/td.vue/dist_electron/package.json' of 'background.js'. Please either fix that or report it to the module author
(Use `electron --trace-deprecation ...` to show where the warning was created)
(node:234607) ExtensionLoadWarning: Warnings loading extension at /home/adamjablonski/.config/Threat Dragon/extensions/nhdogjmejiglipccpnnnanhbledajbpd:
  Manifest version 2 is deprecated, and support will be removed in 2023. See https://developer.chrome.com/blog/mv2-transition/ for more details.
Crashing due to FD ownership violation:
#0 0x56107bf647a3 <unknown>
#1 0x56107c0107dc <unknown>
#2 0x56107c0107a1 <unknown>
#3 0x7f8341de8cdb <unknown>```

I think my system lacks some lib, so if you have any idea, please give me advice :) 
jgadsden commented 2 years ago

Thanks for the bug report @dzablo . If you have a fix then that would be great ... no harm in asking ;)

I have added it to the project board: https://github.com/OWASP/threat-dragon/projects/4

dzablo commented 2 years ago

@jgadsden if you can give me advice on how to debug it I will try to find where is the issue,

jgadsden commented 2 years ago

Hello @dzablo

These are the steps I took to try and reproduce this:

  1. clone the repo, install and then run pnpm run start:desktop
  2. 'Login with local session'
  3. 'Import a threat model via JSON'
  4. paste the contents of test.json.log
  5. 'Import'
  6. 'Report'
  7. 'Print'
  8. 'Save as PDF' from 'PDF' pull-down
  9. 'Save'

this gave me file OWASP Threat Dragon.pdf

Can you try this again? I will create a Cypress e2e test for this so we can continually check that it is working

dzablo commented 2 years ago

I still get the same issue

pnpm run start:desktop

> threat-dragon@2.0.0 start:desktop $HOME/git/tools/threat-dragon
> cd td.vue && npm run electron:serve

> threat-dragon-frontend@2.0.0 electron:serve
> vue-cli-service electron:serve

Server API protocol: http and port: 3000
 INFO  Starting development server...

 WARNING  Compiled with 2 warnings                                                                                                                                                                                                                                     11:50:42 AM

 warning  in ./src/App.vue?vue&type=style&index=0&id=7ba5bd90&lang=scss&

Module Warning (from ./node_modules/.pnpm/postcss-loader@6.2.1_mepnsno3xmng6eyses4tepu7bu/node_modules/postcss-loader/dist/cjs.js):
Warning

(3294:3) autoprefixer: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.

 warning  in ./src/components/DashboardAction.vue?vue&type=style&index=0&id=4ed74a2c&lang=scss&scoped=true&

Module Warning (from ./node_modules/.pnpm/postcss-loader@6.2.1_mepnsno3xmng6eyses4tepu7bu/node_modules/postcss-loader/dist/cjs.js):
Warning

(3293:3) autoprefixer: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.

  App running at:
  - Local:   http://localhost:8080/ 
  - Network: http://192.168.15.50:8080/

  Note that the development build is not optimized.
  To create a production build, run pnpm run build.

Error: Could not find a package.json for module ajv
    at $HOME/git/tools/threat-dragon/td.vue/node_modules/.pnpm/vue-cli-plugin-electron-builder@2.1.1/node_modules/vue-cli-plugin-electron-builder/lib/webpackConfig.js:149:17
    at Array.reduce (<anonymous>)
    at getExternals ($HOME/git/tools/threat-dragon/td.vue/node_modules/.pnpm/vue-cli-plugin-electron-builder@2.1.1/node_modules/vue-cli-plugin-electron-builder/lib/webpackConfig.js:111:41)
    at bundleMain ($HOME/git/tools/threat-dragon/td.vue/node_modules/.pnpm/vue-cli-plugin-electron-builder@2.1.1/node_modules/vue-cli-plugin-electron-builder/index.js:602:20)
    at startElectron ($HOME/git/tools/threat-dragon/td.vue/node_modules/.pnpm/vue-cli-plugin-electron-builder@2.1.1/node_modules/vue-cli-plugin-electron-builder/index.js:316:49)
    at $HOME/git/tools/threat-dragon/td.vue/node_modules/.pnpm/vue-cli-plugin-electron-builder@2.1.1/node_modules/vue-cli-plugin-electron-builder/index.js:408:7
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
⠇  Bundling main process...

 DONE  Compiled successfully in 993ms                                                                                                                                                                                                                                  11:50:43 AM

  File                     Size                                                                                                                      Gzipped

  dist-desktop/index.js    1335.24 KiB                                                                                                               293.32 KiB

  Images and other types of assets omitted.
  Build at: 2022-09-13T09:50:43.787Z - Hash: 856df6e0e669dc869b92 - Time: 993ms

 INFO  Launching Electron...
11:50:44.285 › update-electron-app config looks good; aborting updates since app is in development mode
(node:205942) [DEP0128] DeprecationWarning: Invalid 'main' field in '$HOME/git/tools/threat-dragon/td.vue/dist-desktop/package.json' of 'background.js'. Please either fix that or report it to the module author
(Use `electron --trace-deprecation ...` to show where the warning was created)
(node:205942) ExtensionLoadWarning: Warnings loading extension at $HOME/.config/Threat Dragon/extensions/nhdogjmejiglipccpnnnanhbledajbpd:
  Manifest version 2 is deprecated, and support will be removed in 2023. See https://developer.chrome.com/blog/mv2-transition/ for more details.
11:50:44.510 › Log level is set to: info
11:50:44.511 › Running in development mode with WEBPACK_DEV_SERVER_URL: http://localhost:8080/
Crashing due to FD ownership violation:
#0 0x565065d8cc53 <unknown>
#1 0x565065e38c8c <unknown>
#2 0x565065e38c51 <unknown>
#3 0x7f5bb3202ef3 <unknown>
jgadsden commented 2 years ago

Thanks @dzablo The difference I see in my console output is that you have:

Error: Could not find a package.json for module ajv
    at $HOME/git/tools/threat-dragon/td.vue/node_modules/.pnpm/vue-cli-plugin-electron-builder@2.1.1/node_modules/vue-cli-plugin-electron-builder/lib/webpackConfig.js:149:17
    at Array.reduce (<anonymous>)
...

This looks like pnpm install is either out of date or needs to be run again. Could you install again and make sure you are not getting Could not find a package.json errors?

You can always try a pnpm run clean and then a pnpm install

dzablo commented 2 years ago

@jgadsden I still get the error :/

pnpm run start:desktop

> threat-dragon@2.0.0 start:desktop $HOME/git/tools/threat-dragon
> cd td.vue && npm run electron:serve

> threat-dragon-frontend@2.0.0 electron:serve
> vue-cli-service electron:serve

Server API protocol: http and port: 3000
 INFO  Starting development server...

 WARNING  Compiled with 2 warnings                                                                                                                                                                                                                                     10:22:42 AM

 warning  in ./src/App.vue?vue&type=style&index=0&id=7ba5bd90&lang=scss&

Module Warning (from ./node_modules/.pnpm/postcss-loader@6.2.1_mepnsno3xmng6eyses4tepu7bu/node_modules/postcss-loader/dist/cjs.js):
Warning

(3294:3) autoprefixer: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.

 warning  in ./src/components/DashboardAction.vue?vue&type=style&index=0&id=4ed74a2c&lang=scss&scoped=true&

Module Warning (from ./node_modules/.pnpm/postcss-loader@6.2.1_mepnsno3xmng6eyses4tepu7bu/node_modules/postcss-loader/dist/cjs.js):
Warning

(3293:3) autoprefixer: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.

  App running at:
  - Local:   http://localhost:8080/ 
  - Network: http://192.168.15.150:8080/

  Note that the development build is not optimized.
  To create a production build, run pnpm run build.

⠹  Bundling main process...

 DONE  Compiled successfully in 1195ms                                                                                                                                                                                                                                 10:22:44 AM

  File                     Size                                                                                                                      Gzipped

  dist-desktop/index.js    1335.24 KiB                                                                                                               293.32 KiB

  Images and other types of assets omitted.
  Build at: 2022-09-15T08:22:44.114Z - Hash: 856df6e0e669dc869b92 - Time: 1195ms

 INFO  Launching Electron...
10:22:44.670 › update-electron-app config looks good; aborting updates since app is in development mode
(node:438132) [DEP0128] DeprecationWarning: Invalid 'main' field in '$HOME/git/tools/threat-dragon/td.vue/dist-desktop/package.json' of 'background.js'. Please either fix that or report it to the module author
(Use `electron --trace-deprecation ...` to show where the warning was created)
(node:438132) ExtensionLoadWarning: Warnings loading extension at $HOME/.config/Threat Dragon/extensions/nhdogjmejiglipccpnnnanhbledajbpd:
  Manifest version 2 is deprecated, and support will be removed in 2023. See https://developer.chrome.com/blog/mv2-transition/ for more details.
10:22:44.908 › Log level is set to: info
10:22:44.910 › Running in development mode with WEBPACK_DEV_SERVER_URL: http://localhost:8080/
Crashing due to FD ownership violation:
#0 0x5591dfce8c53 <unknown>
#1 0x5591dfd94c8c <unknown>
#2 0x5591dfd94c51 <unknown>
#3 0x7f44b6d70ef3 <unknown>
dzablo commented 2 years ago

I'm pretty sure it is the same issue https://github.com/electron/electron/issues/31151 because when I call window.print() in the dev console the issue occurs.

jgadsden commented 2 years ago

Many thanks for investigating @dzablo What do we want to do here? I do not want to hold up Threat Dragon Version 2.0, as there does not seem to be a fix from electron. I can tag it Version2.x and wait for a fix from Electron?

dzablo commented 2 years ago

What do we want to do here? I do not want to hold up Threat Dragon Version 2.0, as there does not seem to be a fix from electron. I can tag it Version2.x and wait for a fix from Electron?

I think we can leave it with the tag and wait for the fix, and for the others who have the same problem, I would like to recommend as a workaround to run the pnpm run start:server and use your favorite browser :)

jgadsden commented 2 years ago

Keeping this issue Open until we get a fix from Electron, although it may not get resolved for the upcoming version 2.0 release. Created a wiki FAQ to help

jgadsden commented 1 year ago

Hello @dzablo - can you try with the latest version v2.0.0 of Threat Dragon desktop? Available from the release area

Also are you using a network printer - that may be the problem : https://github.com/electron/electron/issues/31151#issuecomment-1313218193

dzablo commented 1 year ago

@jgadsden sorry, I change the laptop and now works fine, so we can close this issue.

jgadsden commented 1 year ago

cool, thanks @dzablo