mirror of
https://github.com/bitwarden/jslib
synced 2025-12-06 00:03:29 +00:00
validate path for directory traversal (#540)
* validate path for directory traversal * use previously constructed requestUrl
This commit is contained in:
@@ -1609,6 +1609,13 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
authed: boolean, hasResponse: boolean, apiUrl?: string,
|
||||
alterHeaders?: (headers: Headers) => void): Promise<any> {
|
||||
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({
|
||||
'Device-Type': this.deviceType,
|
||||
});
|
||||
@@ -1647,7 +1654,7 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
}
|
||||
|
||||
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) {
|
||||
const responseJson = await response.json();
|
||||
|
||||
Reference in New Issue
Block a user