diff --git a/src/app/core/interceptors/httpInterceptor.spec.ts b/src/app/core/interceptors/httpInterceptor.spec.ts index 61f13bdc72..274d8a2cb2 100644 --- a/src/app/core/interceptors/httpInterceptor.spec.ts +++ b/src/app/core/interceptors/httpInterceptor.spec.ts @@ -83,6 +83,36 @@ describe('HttpConfigInterceptor', () => { expect(httpInterceptor).toBeTruthy(); }); + describe('getUrlWithoutQueryParam:', () => { + it('should return value truncating ;', () => { + const result = httpInterceptor.getUrlWithoutQueryParam( + 'https://staging1.fyle.tech/enterprise/add_edit_expense;dataUrl=data:image%2Fjpeg%3Bbase64,%2F9j' + ); + expect(result).toEqual('https://staging1.fyle.tech/enterprise/add_edit_expense'); + }); + + it('should return value truncating ?', () => { + const result = httpInterceptor.getUrlWithoutQueryParam( + 'https://staging1.fyle.tech/enterprise/add_edit_expense?dataUrl=data:image%2Fjpeg%3Bbase64,%2F9j' + ); + expect(result).toEqual('https://staging1.fyle.tech/enterprise/add_edit_expense'); + }); + + it('should return value truncating ;?', () => { + const result = httpInterceptor.getUrlWithoutQueryParam( + 'https://staging1.fyle.tech/enterprise/add_edit_expense;?dataUrl=data:image%2Fjpeg%3Bbase64,%2F9j' + ); + expect(result).toEqual('https://staging1.fyle.tech/enterprise/add_edit_expense'); + }); + + it('should return value truncating ?;', () => { + const result = httpInterceptor.getUrlWithoutQueryParam( + 'https://staging1.fyle.tech/enterprise/add_edit_expense?;dataUrl=data:image%2Fjpeg%3Bbase64,%2F9j' + ); + expect(result).toEqual('https://staging1.fyle.tech/enterprise/add_edit_expense'); + }); + }); + describe('secureUrl():', () => { it('should return true for a secure URL', () => { const result = httpInterceptor.secureUrl('https://staging1.fyle.tech/app/api/auth/logout'); diff --git a/src/app/core/interceptors/httpInterceptor.ts b/src/app/core/interceptors/httpInterceptor.ts index e4bff7ae62..a857e76d8c 100644 --- a/src/app/core/interceptors/httpInterceptor.ts +++ b/src/app/core/interceptors/httpInterceptor.ts @@ -113,6 +113,20 @@ export class HttpConfigInterceptor implements HttpInterceptor { ); } + getUrlWithoutQueryParam(url: string): string { + const queryIndex = Math.min( + url.indexOf('?') !== -1 ? url.indexOf('?') : url.length, + url.indexOf(';') !== -1 ? url.indexOf(';') : url.length + ); + if (queryIndex !== url.length) { + url = url.substring(0, queryIndex); + } + if (url.length > 200) { + url = url.substring(0, 200); + } + return url; + } + intercept(request: HttpRequest, next: HttpHandler): Observable> { return forkJoin({ token: iif(() => this.secureUrl(request.url), this.getAccessToken(), of(null)), @@ -128,7 +142,13 @@ export class HttpConfigInterceptor implements HttpInterceptor { const osVersion = deviceInfo.osVersion; const operatingSystem = deviceInfo.operatingSystem; const mobileModifiedappVersion = `fyle-mobile::${appVersion}::${operatingSystem}::${osVersion}`; - request = request.clone({ headers: request.headers.set('X-App-Version', mobileModifiedappVersion) }); + request = request.clone({ + setHeaders: { + 'X-App-Version': mobileModifiedappVersion, + 'X-Page-Url': this.getUrlWithoutQueryParam(window.location.href), + 'X-Source-Identifier': 'mobile_app', + }, + }); return next.handle(request).pipe( catchError((error) => {