validate path for directory traversal (#540)
* validate path for directory traversal * use previously constructed requestUrl
This commit is contained in:
parent
1b4a5508bd
commit
b99103d3f7
|
@ -1609,6 +1609,13 @@ export class ApiService implements ApiServiceAbstraction {
|
||||||
authed: boolean, hasResponse: boolean, apiUrl?: string,
|
authed: boolean, hasResponse: boolean, apiUrl?: string,
|
||||||
alterHeaders?: (headers: Headers) => void): Promise<any> {
|
alterHeaders?: (headers: Headers) => void): Promise<any> {
|
||||||
apiUrl = Utils.isNullOrWhitespace(apiUrl) ? this.environmentService.getApiUrl() : apiUrl;
|
apiUrl = Utils.isNullOrWhitespace(apiUrl) ? this.environmentService.getApiUrl() : apiUrl;
|
||||||
|
|
||||||
|
const requestUrl = apiUrl + path;
|
||||||
|
// Prevent directory traversal from malicious paths
|
||||||
|
if (new URL(requestUrl).href !== requestUrl) {
|
||||||
|
return Promise.reject('Invalid request url path.');
|
||||||
|
}
|
||||||
|
|
||||||
const headers = new Headers({
|
const headers = new Headers({
|
||||||
'Device-Type': this.deviceType,
|
'Device-Type': this.deviceType,
|
||||||
});
|
});
|
||||||
|
@ -1647,7 +1654,7 @@ export class ApiService implements ApiServiceAbstraction {
|
||||||
}
|
}
|
||||||
|
|
||||||
requestInit.headers = headers;
|
requestInit.headers = headers;
|
||||||
const response = await this.fetch(new Request(apiUrl + path, requestInit));
|
const response = await this.fetch(new Request(requestUrl, requestInit));
|
||||||
|
|
||||||
if (hasResponse && response.status === 200) {
|
if (hasResponse && response.status === 200) {
|
||||||
const responseJson = await response.json();
|
const responseJson = await response.json();
|
||||||
|
|
Loading…
Reference in New Issue