Skip to content

Commit

Permalink
update @ProtonMail web clients, closes #598
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiry committed Mar 13, 2023
1 parent 348f13f commit 936eb7e
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 27 deletions.
28 changes: 28 additions & 0 deletions patches/protonmail/common-3.patch
Expand Up @@ -125,3 +125,31 @@ index 36bd0c712..c2fb3681c 100644
if (doesNotSupportEarlyAccessVersion()) {
return;
}

diff --git a/applications/mail/src/app/helpers/message/messageImages.ts b/applications/mail/src/app/helpers/message/messageImages.ts
index effa61709..2d54ff153 100644
--- a/applications/mail/src/app/helpers/message/messageImages.ts
+++ b/applications/mail/src/app/helpers/message/messageImages.ts
@@ -194,7 +194,7 @@ export const replaceProxyWithOriginalURLAttributes = (message: MessageState, doc

export const forgeImageURL = (url: string, uid: string) => {
const config = getImage(url, 0, uid);
- const prefixedUrl = `api/${config.url}`; // api/ is required to set the AUTH cookie
+ const prefixedUrl = `___ELECTRON_MAIL_PROTON_API_ENTRY_URL_PLACEHOLDER___/${config.url}`;
const urlToLoad = createUrl(prefixedUrl, config.params);
return urlToLoad.toString();
};

diff --git a/packages/components/containers/contacts/helpers/senderImage.ts b/packages/components/containers/contacts/helpers/senderImage.ts
index 24578bbc0..6b38625e0 100644
--- a/packages/components/containers/contacts/helpers/senderImage.ts
+++ b/packages/components/containers/contacts/helpers/senderImage.ts
@@ -58,7 +58,7 @@ export const getSenderImageUrl = (
mode?: SenderImageMode
) => {
const config = getLogo(emailAddress, size, bimiSelector, mode, UID);
- const prefixedUrl = `api/${config.url}`; // api/ is required to set the AUTH cookie
+ const prefixedUrl = `___ELECTRON_MAIL_PROTON_API_ENTRY_URL_PLACEHOLDER___/${config.url}`;
const url = createUrl(prefixedUrl, config.params);
return url.toString();
};
24 changes: 0 additions & 24 deletions patches/protonmail/constants-9.patch

This file was deleted.

4 changes: 2 additions & 2 deletions patches/protonmail/meta.json
Expand Up @@ -49,8 +49,8 @@
"proton-vpn-settings": [
"common-3.patch",
"url-3.patch",
"constants-8.patch",
"sentry-10.patch",
"constants-10.patch",
"sentry-11.patch",
"pack-api-arg-4.patch",
"pack-webpack-6.patch",
"session-storage-5.patch",
Expand Down
188 changes: 188 additions & 0 deletions patches/protonmail/sentry-11.patch
@@ -0,0 +1,188 @@
diff --git a/packages/shared/lib/helpers/sentry.ts b/packages/shared/lib/helpers/sentry.ts
index 69e21214b..6d6a3fb2a 100644
--- a/packages/shared/lib/helpers/sentry.ts
+++ b/packages/shared/lib/helpers/sentry.ts
@@ -1,14 +1,9 @@
import {
captureException,
- configureScope,
- init,
- makeFetchTransport,
captureMessage as sentryCaptureMessage,
} from '@sentry/browser';
-import { BrowserTransportOptions } from '@sentry/browser/types/transports/types';

import { VPN_HOSTNAME } from '../constants';
-import { ApiError } from '../fetch/ApiError';
import { getUIDHeaders } from '../fetch/headers';
import { ProtonConfig } from '../interfaces';

@@ -61,21 +56,6 @@ export const getContentTypeHeaders = (input: RequestInfo | URL): HeadersInit =>
return {};
};

-const sentryFetch = (input: RequestInfo | URL, init?: RequestInit) => {
- return globalThis.fetch(input, {
- ...init,
- headers: {
- ...init?.headers,
- ...getContentTypeHeaders(input),
- ...context.authHeaders,
- },
- });
-};
-
-const makeProtonFetchTransport = (options: BrowserTransportOptions) => {
- return makeFetchTransport(options, sentryFetch);
-};
-
const isLocalhost = (host: string) => host.startsWith('localhost');
const isProduction = (host: string) => host.endsWith('.proton.me') || host === VPN_HOSTNAME;

@@ -94,143 +74,10 @@ function main({
sessionTracking = false,
sentryConfig = getDefaultSentryConfig(config),
ignore = ({ host }) => isLocalhost(host),
-}: SentryOptions) {
- const { SENTRY_DSN, APP_VERSION } = config;
- const { host, release, environment } = sentryConfig;
-
- // No need to configure it if we don't load the DSN
- if (!SENTRY_DSN || ignore(sentryConfig)) {
- return;
- }
+}: SentryOptions) {}

- setUID(uid);
-
- // Assumes SENTRY_DSN is: https://111b3eeaaec34cae8e812df705690a36@sentry/11
- // To get https://111b3eeaaec34cae8e812df705690a36@protonmail.com/api/core/v4/reports/sentry/11
- const dsn = SENTRY_DSN.replace('sentry', `${host}/api/core/v4/reports/sentry`);
-
- init({
- dsn,
- release,
- environment,
- normalizeDepth: 5,
- transport: makeProtonFetchTransport,
- autoSessionTracking: sessionTracking,
- // Disable client reports. Client reports are used by sentry to retry events that failed to send on visibility change.
- // Unfortunately Sentry does not use the custom transport for those, and thus fails to add the headers the API requires.
- sendClientReports: false,
- beforeSend(event, hint) {
- const error = hint?.originalException;
- const stack = typeof error === 'string' ? error : error?.stack;
- // Filter out broken ferdi errors
- if (stack && stack.match(/ferdi|franz/i)) {
- return null;
- }
-
- // Not interested in uncaught API errors
- if (error instanceof ApiError) {
- return null;
- }
-
- if (!context.enabled) {
- return null;
- }
-
- // Remove the hash from the request URL and navigation breadcrumbs to avoid
- // leaking the search parameters of encrypted searches
- if (event.request && event.request.url) {
- [event.request.url] = event.request.url.split('#');
- }
- if (event.breadcrumbs) {
- event.breadcrumbs = event.breadcrumbs.map((breadcrumb) => {
- if (breadcrumb.category === 'navigation' && breadcrumb.data) {
- [breadcrumb.data.from] = breadcrumb.data.from.split('#');
- [breadcrumb.data.to] = breadcrumb.data.to.split('#');
- }
- return breadcrumb;
- });
- }
-
- return event;
- },
- // Some ignoreErrors and denyUrls are taken from this gist: https://gist.github.com/Chocksy/e9b2cdd4afc2aadc7989762c4b8b495a
- // This gist is suggested in the Sentry documentation: https://docs.sentry.io/clients/javascript/tips/#decluttering-sentry
- ignoreErrors: [
- // Ignore random plugins/extensions
- 'top.GLOBALS',
- 'canvas.contentDocument',
- 'MyApp_RemoveAllHighlights',
- 'atomicFindClose',
- // See http://toolbar.conduit.com/Developer/HtmlAndGadget/Methods/JSInjection.aspx
- 'conduitPage',
- // https://bugzilla.mozilla.org/show_bug.cgi?id=1678243
- 'XDR encoding failure',
- 'Request timed out',
- 'No network connection',
- 'Failed to fetch',
- 'NetworkError when attempting to fetch resource.',
- 'webkitExitFullScreen', // Bug in Firefox for iOS.
- 'InactiveSession',
- 'UnhandledRejection', // Happens too often in extensions and we have lints for that, so should be safe to ignore.
- /chrome-extension/,
- /moz-extension/,
- 'TransferCancel', // User action to interrupt upload or download in Drive.
- 'UploadConflictError', // User uploading the same file again in Drive.
- 'UploadUserError', // Upload error on user's side in Drive.
- 'ValidationError', // Validation error on user's side in Drive.
- 'ChunkLoadError', // WebPack loading source code.
- /ResizeObserver loop/, // Chromium bug https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded
- // See: http://blog.errorception.com/2012/03/tale-of-unfindable-js-error.html
- 'originalCreateNotification',
- 'http://tt.epicplay.com',
- "Can't find variable: ZiteReader",
- 'jigsaw is not defined',
- 'ComboSearch is not defined',
- 'http://loading.retry.widdit.com/',
- // Facebook borked
- 'fb_xd_fragment',
- // ISP "optimizing" proxy - `Cache-Control: no-transform` seems to reduce this. (thanks @acdha)
- // See http://stackoverflow.com/questions/4113268/how-to-stop-javascript-injection-from-vodafone-proxy
- 'bmi_SafeAddOnload',
- 'EBCallBackMessageReceived',
- // Avast extension error
- '_avast_submit',
- ],
- denyUrls: [
- // Google Adsense
- /pagead\/js/i,
- // Facebook flakiness
- /graph\.facebook\.com/i,
- // Facebook blocked
- /connect\.facebook\.net\/en_US\/all\.js/i,
- // Woopra flakiness
- /eatdifferent\.com\.woopra-ns\.com/i,
- /static\.woopra\.com\/js\/woopra\.js/i,
- // Chrome extensions
- /extensions\//i,
- /^chrome:\/\//i,
- // Other plugins
- /127\.0\.0\.1:4001\/isrunning/i, // Cacaoweb
- /webappstoolbarba\.texthelp\.com\//i,
- /metrics\.itunes\.apple\.com\.edgesuite\.net\//i,
- ],
- });
-
- configureScope((scope) => {
- scope.setTag('appVersion', APP_VERSION);
- });
-}
-
-export const traceError = (...args: Parameters<typeof captureException>) => {
- if (!isLocalhost(window.location.host)) {
- captureException(...args);
- }
-};
+export const traceError = (...args: Parameters<typeof captureException>) => console.error(...args);

-export const captureMessage = (...args: Parameters<typeof sentryCaptureMessage>) => {
- if (!isLocalhost(window.location.host)) {
- sentryCaptureMessage(...args);
- }
-};
+export const captureMessage = (...args: Parameters<typeof sentryCaptureMessage>) => console.log(...args);

export default main;
2 changes: 1 addition & 1 deletion src/shared/const/proton-apps.ts
Expand Up @@ -76,7 +76,7 @@ export const PROVIDER_REPO_MAP = {
basePath: "account/vpn",
apiSubdomain: "account-api",
repoRelativeDistDir: "./dist",
tag: "proton-vpn-settings@5.0.15.1",
tag: "proton-vpn-settings@5.0.16.0",
protonPack: {},
},
} as const;
Expand Down

0 comments on commit 936eb7e

Please sign in to comment.