You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-02 17:02:31 +03:00
Time out verification attempts after 10 minutes of inactivity
Fixes https://github.com/vector-im/riot-web/issues/10117
This commit is contained in:
@@ -22,6 +22,9 @@ limitations under the License.
|
|||||||
import {MatrixEvent} from '../../models/event';
|
import {MatrixEvent} from '../../models/event';
|
||||||
import {EventEmitter} from 'events';
|
import {EventEmitter} from 'events';
|
||||||
import logger from '../../logger';
|
import logger from '../../logger';
|
||||||
|
import {newTimeoutError} from "./Error";
|
||||||
|
|
||||||
|
const timeoutException = new Error("Verification timed out");
|
||||||
|
|
||||||
export default class VerificationBase extends EventEmitter {
|
export default class VerificationBase extends EventEmitter {
|
||||||
/**
|
/**
|
||||||
@@ -63,6 +66,21 @@ export default class VerificationBase extends EventEmitter {
|
|||||||
this._parent = parent;
|
this._parent = parent;
|
||||||
this._done = false;
|
this._done = false;
|
||||||
this._promise = null;
|
this._promise = null;
|
||||||
|
this._transactionTimeoutTimer = null;
|
||||||
|
|
||||||
|
// At this point, the verification request was received so start the timeout timer.
|
||||||
|
this._pingTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
_pingTransaction() {
|
||||||
|
console.log("Refreshing/starting the verification transaction timeout timer");
|
||||||
|
clearTimeout(this._transactionTimeoutTimer);
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!this._done) {
|
||||||
|
console.log("Triggering verification timeout");
|
||||||
|
this.cancel(timeoutException);
|
||||||
|
}
|
||||||
|
}, 10 * 60 * 1000); // 10 minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendToDevice(type, content) {
|
_sendToDevice(type, content) {
|
||||||
@@ -92,6 +110,7 @@ export default class VerificationBase extends EventEmitter {
|
|||||||
} else if (e.getType() === this._expectedEvent) {
|
} else if (e.getType() === this._expectedEvent) {
|
||||||
this._expectedEvent = undefined;
|
this._expectedEvent = undefined;
|
||||||
this._rejectEvent = undefined;
|
this._rejectEvent = undefined;
|
||||||
|
this._pingTransaction();
|
||||||
this._resolveEvent(e);
|
this._resolveEvent(e);
|
||||||
} else {
|
} else {
|
||||||
this._expectedEvent = undefined;
|
this._expectedEvent = undefined;
|
||||||
@@ -119,7 +138,10 @@ export default class VerificationBase extends EventEmitter {
|
|||||||
if (this.userId && this.deviceId && this.transactionId) {
|
if (this.userId && this.deviceId && this.transactionId) {
|
||||||
// send a cancellation to the other user (if it wasn't
|
// send a cancellation to the other user (if it wasn't
|
||||||
// cancelled by the other user)
|
// cancelled by the other user)
|
||||||
if (e instanceof MatrixEvent) {
|
if (e === timeoutException) {
|
||||||
|
const timeoutEvent = newTimeoutError();
|
||||||
|
this._sendToDevice(timeoutEvent.getType(), timeoutEvent.getContent());
|
||||||
|
} else if (e instanceof MatrixEvent) {
|
||||||
const sender = e.getSender();
|
const sender = e.getSender();
|
||||||
if (sender !== this.userId) {
|
if (sender !== this.userId) {
|
||||||
const content = e.getContent();
|
const content = e.getContent();
|
||||||
@@ -177,6 +199,7 @@ export default class VerificationBase extends EventEmitter {
|
|||||||
});
|
});
|
||||||
if (this._doVerification && !this._started) {
|
if (this._doVerification && !this._started) {
|
||||||
this._started = true;
|
this._started = true;
|
||||||
|
this._pingTransaction(); // restart the timeout
|
||||||
Promise.resolve(this._doVerification())
|
Promise.resolve(this._doVerification())
|
||||||
.then(this.done.bind(this), this.cancel.bind(this));
|
.then(this.done.bind(this), this.cancel.bind(this));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user