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

feat: updated webrtc implementation #519

Merged
merged 2 commits into from
May 22, 2024
Merged

Conversation

ThaUnknown
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[ ] Bug fix
[x] New feature
[ ] Other, please explain:

What changes did you make? (Give an overview)
Include WebRTC on node, drop wrtc
Which issue (if any) does this pull request address?

Is there anything you'd like reviewers to focus on?

Copy link

socket-security bot commented May 14, 2024

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSource
Install scripts npm/node-datachannel@0.9.0
  • Install script: install
  • Source: prebuild-install -r napi || (npm install --ignore-scripts --production=false && npm run _prebuild)
  • orphan: npm/node-datachannel@0.9.0

View full report↗︎

Next steps

What is an install script?

Install scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.

Packages should not be running non-essential scripts during install and there are often solutions to problems people solve with install scripts that can be run at publish time instead.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

  • @SocketSecurity ignore npm/node-datachannel@0.9.0

@ThaUnknown ThaUnknown force-pushed the wrtc branch 2 times, most recently from d88ba03 to 594307c Compare May 14, 2024 21:17
@ThaUnknown
Copy link
Member Author

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package Note Source
Install scripts npm/node-datachannel@0.7.0

  • Install script: install

  • Source: prebuild-install -r napi || (npm install --ignore-scripts --production=false && npm run _prebuild)

  • package.json

View full report↗︎

Next steps

** What is an install script? **
** Take a deeper look at the dependency **
** Remove the package **
Mark a package as acceptable risk

@SocketSecurity ignore npm/node-datachannel@0.7.0

@ThaUnknown ThaUnknown enabled auto-merge (squash) May 22, 2024 21:36
@ThaUnknown ThaUnknown disabled auto-merge May 22, 2024 21:37
@ThaUnknown ThaUnknown force-pushed the wrtc branch 2 times, most recently from e36e91d to 68c3c05 Compare May 22, 2024 21:48
@ThaUnknown ThaUnknown merged commit 633d68a into webtorrent:master May 22, 2024
2 of 3 checks passed
@ThaUnknown ThaUnknown deleted the wrtc branch May 22, 2024 21:52
webtorrent-bot pushed a commit that referenced this pull request May 22, 2024
# [11.1.0](v11.0.2...v11.1.0) (2024-05-22)

### Bug Fixes

* semantic release ([#520](#520)) ([428fb22](428fb22))

### Features

* updated webrtc implementation ([#519](#519)) ([633d68a](633d68a))
@webtorrent-bot
Copy link

🎉 This PR is included in version 11.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jarylc
Copy link

jarylc commented May 24, 2024

It seems after this change which indirectly depends on npm/node-datachannel@0.7.0, the total dependency size has shot up substantially from this dependency alone (likely due to the new compilation steps)

ncdu 1.20 ~ Use the arrow keys to navigate, press ? for help                                                                                                                                                                                                                                                     
--- /usr/local/lib/node_modules/bittorrent-tracker/node_modules ---
                                                          /..                                                                                                                                                                                                                                                    
  655.8 MiB [###########################################] /node-datachannel
    8.7 MiB [                                           ] /web-streams-polyfill
  772.0 KiB [                                           ] /utf-8-validate
  428.0 KiB [                                           ] /bufferutil
  316.0 KiB [                                           ] /ip-address
  268.0 KiB [                                           ] /semver
  228.0 KiB [                                           ] /socks
  220.0 KiB [                                           ] /@thaunknown
  212.0 KiB [                                           ] /event-target-shim
  188.0 KiB [                                           ] /readable-stream
  180.0 KiB [                                           ] /ws
  168.0 KiB [                                           ] /smart-buffer
  164.0 KiB [                                           ] /node-domexception
*Total disk usage: 670.2 MiB   Apparent size: 611.1 MiB   Items: 23506

In previous versions, web-streams-polyfill was the biggest dependency.

I think it's a good idea to take note of this.

EDIT:

RUN mkdir -p node-datachannel/build/Release/ && \
    mv node_modules/node-datachannel/package.json node_modules/node-datachannel/lib node-datachannel/ && \
    mv node_modules/node-datachannel/build/Release/node_datachannel.node node-datachannel/build/Release/ && \
    rm -rf node_modules/node-datachannel/ && \
    mv node-datachannel node_modules/

For now, I'm adding this to my Docker image build process after running install to remove all unused remnants of the build process

@ThaUnknown
Copy link
Member Author

not sure what to tell you
image

@jarylc
Copy link

jarylc commented May 24, 2024

not sure what to tell you image

Hmm that's very weird, maybe it's only on OSes that require compilation or some sort (Alpine Linux in this case)

Compilation seems to pulls the entire git repository of node-datachannel and that is where the bulk of the remnant files.

I did notice there was a prebuilt folder in the node module folder maybe it's using that for Windows and compiles on Linux.

@ThaUnknown
Copy link
Member Author

I think this is something to bring up with node-datachannel, not webtorrent

@jarylc
Copy link

jarylc commented May 24, 2024

I think this is something to bring up with node-datachannel, not webtorrent

Yep do agree, will raise an issue there.

@Chocobozzz
Copy link
Contributor

Hi,

Like said above, this PR adds node-datachannel dependency (used by webrtc-polyfill introduced by @thaunknown/simple-peer > 10) which can break dependency installation on some distributions.

I don't think simple-peer (and so bittorrent-tracker) should require the prebuilt node-datachannel dependency, especially in the case of bittorrent-tracker where it may be used in server mode only (where simple-peer is not used) or in web browser context.

@ThaUnknown
Copy link
Member Author

where simple-peer is not used

it is used, ws trackers were always supported in node.js, simply webrtc wasn't, now that it is, ws trackers work correctly too

@Chocobozzz
Copy link
Contributor

I meant using the bittorrent-tracker by just importing the Server from https://github.com/webtorrent/bittorrent-tracker/blob/master/server.js

From what I can see simple-peer is not used in the server files, but I may be wrong?

@ThaUnknown
Copy link
Member Author

right, but there's no package separation between server and client, anyways this isn't changing, it's staying

ndc compiles just fine on alpine so idk what the issue is

@Chocobozzz
Copy link
Contributor

ndc compiles just fine on alpine so idk what the issue is

Unfortunately there are other build issues, on FreeBSD this time: Chocobozzz/PeerTube#6502

I'm not sure to understand why your simple-peer package doesn't use the wrtc option so it's the responsibility of the library consumer to choose if it wants the native webrtc dependency?

Because the new bittorrent-tracker versions force every consumer to install a native dependency for a very specific use case (use the bittorrent-tracker in client mode, in a node.js ecosystem where webrtc is not available).

What do you think of publishing another package that would not rely on node-datachannel, @thaunknown/simple-peer-lite for example, that bittorrent-tracker may use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants