mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[AAE-12501] Replace Math.random() to fix hospot security issue, fix lint issues
This commit is contained in:
@@ -43,9 +43,7 @@ import { AlfrescoApiResponseError } from './alfresco-api/alfresco-api.response-e
|
|||||||
import { Constructor } from './types';
|
import { Constructor } from './types';
|
||||||
import { RequestOptions, SecurityOptions } from './interfaces';
|
import { RequestOptions, SecurityOptions } from './interfaces';
|
||||||
import { AppConfigService, AppConfigValues } from '../../../src/lib/app-config/app-config.service';
|
import { AppConfigService, AppConfigValues } from '../../../src/lib/app-config/app-config.service';
|
||||||
import ee from 'event-emitter';
|
import ee, { Emitter } from 'event-emitter';
|
||||||
import { Emitter } from 'event-emitter';
|
|
||||||
|
|
||||||
|
|
||||||
export interface Emitters {
|
export interface Emitters {
|
||||||
readonly eventEmitter: Emitter;
|
readonly eventEmitter: Emitter;
|
||||||
@@ -142,19 +140,19 @@ export class AdfHttpClient implements ee.Emitter,JsApiHttpClient {
|
|||||||
|
|
||||||
private addPromiseListeners<T = any>(promise: Promise<T>, eventEmitter: any) {
|
private addPromiseListeners<T = any>(promise: Promise<T>, eventEmitter: any) {
|
||||||
const eventPromise = Object.assign(promise, {
|
const eventPromise = Object.assign(promise, {
|
||||||
on: function () {
|
on() {
|
||||||
eventEmitter.on.apply(eventEmitter, arguments);
|
eventEmitter.on.apply(eventEmitter, arguments);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
once: function () {
|
once() {
|
||||||
eventEmitter.once.apply(eventEmitter, arguments);
|
eventEmitter.once.apply(eventEmitter, arguments);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
emit: function () {
|
emit() {
|
||||||
eventEmitter.emit.apply(eventEmitter, arguments);
|
eventEmitter.emit.apply(eventEmitter, arguments);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
off: function () {
|
off() {
|
||||||
eventEmitter.off.apply(eventEmitter, arguments);
|
eventEmitter.off.apply(eventEmitter, arguments);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -168,12 +166,12 @@ export class AdfHttpClient implements ee.Emitter,JsApiHttpClient {
|
|||||||
on: this.on.bind(this),
|
on: this.on.bind(this),
|
||||||
off: this.off.bind(this),
|
off: this.off.bind(this),
|
||||||
once: this.once.bind(this),
|
once: this.once.bind(this),
|
||||||
emit: this.emit.bind(this),
|
emit: this.emit.bind(this)
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
apiClientEmitter: apiClientEmitter,
|
apiClientEmitter,
|
||||||
eventEmitter: ee({}),
|
eventEmitter: ee({})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +236,6 @@ export class AdfHttpClient implements ee.Emitter,JsApiHttpClient {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return this.addPromiseListeners(promise, eventEmitter);
|
return this.addPromiseListeners(promise, eventEmitter);
|
||||||
// return promise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getBody(options: RequestOptions): any {
|
private static getBody(options: RequestOptions): any {
|
||||||
@@ -287,7 +284,8 @@ export class AdfHttpClient implements ee.Emitter,JsApiHttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private createCSRFToken(a?: any): string {
|
private createCSRFToken(a?: any): string {
|
||||||
return a ? (a ^ ((Math.random() * 16) >> (a / 4))).toString(16) : ([1e16] + (1e16).toString()).replace(/[01]/g, this.createCSRFToken);
|
const randomValue = window.crypto.getRandomValues(new Uint32Array(1))[0];
|
||||||
|
return a ? (a ^ ((randomValue * 16) >> (a / 4))).toString(16) : ([1e16] + (1e16).toString()).replace(/[01]/g, this.createCSRFToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getResponseType(options: RequestOptions): 'blob' | 'json' | 'text' {
|
private static getResponseType(options: RequestOptions): 'blob' | 'json' | 'text' {
|
||||||
|
|||||||
Reference in New Issue
Block a user