Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Removed the max length validation from the `authentication.authenticate` API.",
"packageName": "@microsoft/teams-js",
"email": "jeklouda@microsoft.com",
"dependentChangeType": "patch"
}
4 changes: 2 additions & 2 deletions packages/teams-js/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,12 @@ export function validateId(id: string, errorToThrow?: Error): void {
}
}

export function validateUrl(url: URL, errorToThrow?: Error): void {
export function validateUrl(url: URL, errorToThrow?: Error, enforceMaxLength: boolean = true): void {
Comment thread
ndangudubiyyam marked this conversation as resolved.
Outdated
const urlString = url.toString().toLocaleLowerCase();
if (hasScriptTags(urlString)) {
throw errorToThrow || new Error('Invalid Url');
}
if (urlString.length > 2048) {
if (enforceMaxLength && urlString.length > 2048) {
throw errorToThrow || new Error('Url exceeds the maximum size of 2048 characters');
}
if (!isValidHttpsURL(url)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/teams-js/src/public/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async function authenticateHelper(
): Promise<string> {
// Convert any relative URLs into absolute URLs before sending them over to the parent window.
const fullyQualifiedURL: URL = fullyQualifyUrlString(authenticateParameters.url);
validateUrl(fullyQualifiedURL);
validateUrl(fullyQualifiedURL, undefined, false);

// Ask the parent window to open an authentication window with the parameters provided by the caller.
return sendMessageToParentAsync<[boolean, string]>(apiVersionTag, 'authentication.authenticate', [
Expand Down
7 changes: 6 additions & 1 deletion packages/teams-js/test/internal/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ describe('utils', () => {
expect(error).toEqual(new Error('Invalid Url'));
}
});
it('should throw maxlength exceed error if it contains more than 2048 chars', async () => {
it('should throw maxlength exceed error if enforceMaxLength is true and URL contains more than 2048 chars', async () => {
expect.assertions(1);
const url = 'https://example.com?param=' + 'a'.repeat(2048);
try {
Expand All @@ -277,6 +277,11 @@ describe('utils', () => {
expect(error).toEqual(new Error('Url exceeds the maximum size of 2048 characters'));
}
});
it('should not throw maxlength exceed error if enforceMaxLength is false and URL contains more than 2048 chars', async () => {
expect.assertions(1);
const url = 'https://example.com?param=' + 'a'.repeat(2048);
expect(() => validateUrl(new URL(url), undefined, false)).not.toThrow();
});
it('should throw invalid url error if it non http url', async () => {
expect.assertions(1);
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
Expand Down
Loading