Skip to content

Commit

Permalink
Prevent verto RPCs without node_id (#461)
Browse files Browse the repository at this point in the history
* add checks for bad cases between invite and hangup

* remove check for undocumented methods

* add changeset
  • Loading branch information
edolix authored Mar 17, 2022
1 parent 8f6e681 commit da4ef02
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/many-planets-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/webrtc': patch
---

Prevent BaseConnection RPCs without a `node_id`.
19 changes: 18 additions & 1 deletion packages/webrtc/src/BaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class BaseConnection<EventTypes extends EventEmitter.ValidEventTypes>
* Verto messages have to be wrapped into an execute
* request and sent using the 'video.message' method.
*/
public vertoExecute(vertoMessage: JSONRPCRequest) {
private vertoExecute(vertoMessage: JSONRPCRequest) {
const params: any = {
message: vertoMessage,
node_id: this.nodeId,
Expand All @@ -225,6 +225,14 @@ export class BaseConnection<EventTypes extends EventEmitter.ValidEventTypes>
} else {
params.subscribe = this.getSubscriptions()
}
} else {
// nodeId is required for all the requests (except for verto.invite)
if (!this.nodeId) {
this.logger.warn(
`Skip Request. Missing nodeId for '${vertoMessage.method}'.`
)
return
}
}

return this.execute({
Expand Down Expand Up @@ -539,6 +547,15 @@ export class BaseConnection<EventTypes extends EventEmitter.ValidEventTypes>

/** @internal */
async executeInvite(sdp: string) {
if (this.state !== 'new') {
/**
* Something bad happened. Either App logic invoking
* methods in a wrong order or events are not correct.
*/
throw new Error(
`Invalid state: '${this.state}' for connection id: ${this.id}`
)
}
this.setState('requesting')
try {
const ssOpts = this.options.screenShare
Expand Down

0 comments on commit da4ef02

Please sign in to comment.