Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks to prevent formatting hxxps #405

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions applications/docs-editor/src/app/Utils/sanitizeUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export const sanitizeUrl = (url: string): string | undefined => {
return undefined
}

if (url.toLowerCase().startsWith('hxxps')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check should probably be moved to line 16 and you should use the parsedUrl.protocol for the check. Also check hxxps and hxxp.

return url;
}

let parsedUrl: URL
try {
parsedUrl = new URL(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const sanitizeRelativeHttpLinks = (link: HTMLLinkElement) => {
// link.href is the absolute value of the link: mail.proton.me is prepended, use getAttribute
const url = link.getAttribute('href');

if (url) {
if (url && !url.toLowerCase().startsWith('hxxps')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the customization in this function make any sense at all? A URL is always passed without a protocol and if this starts with hxxps, then in my opinion the http:// should still be added.

Example hxxps.example.com should become http://hxxps.example.com. With your adjustment it will not longer work.

link.setAttribute('href', `http://${url}`);
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/lib/helpers/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ export const getApiSubdomainUrl = (pathname: string, origin: string) => {
};

export const getAppUrlFromApiUrl = (apiUrl: string, appName: APP_NAMES) => {
if (apiUrl.toLowerCase().startsWith('hxxps')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test really make sense in this context?

return new URL(apiUrl);
}
const { subdomain } = APPS_CONFIGURATION[appName];
const url = new URL(apiUrl);
const { hostname } = url;
Expand Down