Skip to content

Commit 3d42f3e

Browse files
author
Edoardo Gallo
authored
Fix relay protocol hijack (#162)
* move _jwtAuth property to BrowserSession * add signature to Relay client * use signature to hijack prev protocol * remove protocol from the storage on disconnect * update js and react-native CHANGELOGs
1 parent 822bd00 commit 3d42f3e

File tree

8 files changed

+19
-32
lines changed

8 files changed

+19
-32
lines changed

packages/common/src/BaseSession.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ADD, REMOVE, SwEvent, BladeMethod, NOTIFICATION_TYPE } from './util/con
1010
import { BroadcastParams, ISignalWireOptions, SubscribeParams, IBladeConnectResult } from './util/interfaces'
1111
import { Subscription, Connect, Reauthenticate } from './messages/Blade'
1212
import { isFunction } from './util/helpers'
13+
import { sessionStorage } from './util/storage/'
1314

1415
export default abstract class BaseSession {
1516
public uuid: string = uuidv4()
@@ -18,6 +19,7 @@ export default abstract class BaseSession {
1819
public nodeid: string
1920
public master_nodeid: string
2021
public expiresAt: number = 0
22+
public signature: string = null
2123
public relayProtocol: string = null
2224
public contexts: string[] = []
2325

@@ -138,6 +140,7 @@ export default abstract class BaseSession {
138140
this.subscriptions = {}
139141
this._autoReconnect = false
140142
this._removeConnection()
143+
await sessionStorage.removeItem(this.signature)
141144
this._executeQueue = []
142145
this._detachListeners()
143146
}
@@ -219,9 +222,10 @@ export default abstract class BaseSession {
219222
const response: IBladeConnectResult = await this.execute(bc).catch(this._handleLoginError)
220223
if (response) {
221224
this._autoReconnect = true
222-
this.relayProtocol = await Setup(this)
223-
const { sessionid, nodeid, master_nodeid, authorization: { expires_at = null } = {} } = response
225+
const { sessionid, nodeid, master_nodeid, authorization: { expires_at = null, signature = null } = {} } = response
224226
this.expiresAt = +expires_at || 0
227+
this.signature = signature
228+
this.relayProtocol = await Setup(this)
225229
this._checkTokenExpiration()
226230
this.sessionid = sessionid
227231
this.nodeid = nodeid

packages/common/src/BrowserSession.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ export default abstract class BrowserSession extends BaseSession {
2222
private _iceServers: RTCIceServer[] = []
2323
private _localElement: HTMLMediaElement = null
2424
private _remoteElement: HTMLMediaElement = null
25-
protected _reconnectDelay: number = 1000
2625

26+
protected _jwtAuth: boolean = true
27+
protected _reconnectDelay: number = 1000
2728
protected _devices: ICacheDevices = {}
2829
protected _audioConstraints: boolean | MediaTrackConstraints = true
2930
protected _videoConstraints: boolean | MediaTrackConstraints = false

packages/common/src/services/Setup.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ const SETUP_CHANNEL = 'notifications'
1010
export default async (session: BaseSession): Promise<string> => {
1111
// TODO: service as an empty string for now. Remove it accordingly to Blade changes
1212
const params: { service: '', protocol?: string } = { service: '' }
13-
const storageKey = `${session.options.project}-setup`
14-
const currentProtocol = await sessionStorage.getItem(storageKey)
15-
if (currentProtocol) {
16-
params.protocol = currentProtocol
13+
const prevProtocol = await sessionStorage.getItem(session.signature)
14+
if (prevProtocol) {
15+
params.protocol = prevProtocol
1716
}
1817
const be = new Execute({ protocol: SETUP_PROTOCOL, method: SETUP_METHOD, params })
1918
const { protocol = null } = await session.execute(be)
2019
if (protocol) {
2120
await session.subscribe({ protocol, channels: [SETUP_CHANNEL] })
22-
await sessionStorage.setItem(storageKey, protocol)
21+
await sessionStorage.setItem(session.signature, protocol)
2322
} else {
2423
logger.error('Error during setup the session protocol.')
2524
}

packages/common/src/util/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface IBladeConnectResult extends IMessageBase {
2424
protocols_uncertified: string[]
2525
authorization: {
2626
expires_at: number
27+
signature: string
2728
}
2829
}
2930

packages/js/CHANGELOG.md

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,8 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

66
## [Unreleased]
7-
### Added
8-
- Expose moderator methods on the Call object.
9-
- A notification that belongs to a Call now contains a reference to the call itself.
10-
- Set/Get default `localElement` for the client to handle the localStream for all calls.
11-
- Set/Get default `remoteElement` for the client to handle the remoteStream for all calls.
12-
- newCall() method now accepts `localElement` and `remoteElement` to override the default ones.
13-
- Set default audio & video settings.
14-
- Expose speedTest() method.
15-
- Force SDP to use plan-b.
16-
- Set default iceServers.
17-
- User can now join conferences without audio & video.
18-
- Expose static method uuid().
19-
- Retrieve supported resolution during client init
20-
- Add property `resolutions` to get supported resolutions.
21-
- Add async method `refreshResolutions()` to refresh cached resolutions
22-
### Changed
23-
- client.connect() is now async to check browser permissions before open the websocket connection.
24-
- client.supportedResolutions() now returns a device list for each resolution supported.
25-
### Removed
26-
- `chatChannel` / `infoChannel` / `conferenceChannel` have been removed from the `conferenceUpdate` notification (**join** & **leave** actions).
7+
### Fixed
8+
- Try to re-establish the previous protocol only if the signature has not changed.
279
### Security
2810
- Update dependencies
2911

packages/js/src/SignalWire.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { Execute } from '../../common/src/messages/Blade'
44
import BaseRequest from '../../common/src/messages/verto/BaseRequest'
55

66
export default class SignalWire extends BrowserSession {
7-
protected _jwtAuth: boolean = true
8-
97
execute(message: BaseMessage) {
108
let msg: BaseMessage = message
119
if (message instanceof BaseRequest) {

packages/react-native/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

66
## [Unreleased]
7+
### Fixed
8+
- Try to re-establish the previous protocol only if the signature has not changed.
79

10+
## [1.0.0] - 2019-06-28
11+
## First Release!
812

913
<!---
1014
### Added

packages/react-native/src/Relay.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { Execute } from '../../common/src/messages/Blade'
44
import BaseRequest from '../../common/src/messages/verto/BaseRequest'
55

66
export default class Relay extends BrowserSession {
7-
protected _jwtAuth: boolean = true
8-
97
execute(message: BaseMessage) {
108
let msg: BaseMessage = message
119
if (message instanceof BaseRequest) {

0 commit comments

Comments
 (0)