Require X-Signal-Timestamp header on all storage/group server 403 responses
Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
parent
ebd360c3a3
commit
0d9cb81130
5 changed files with 70 additions and 5 deletions
|
@ -796,6 +796,10 @@
|
|||
"messageformat": "Failed to send message with endorsements",
|
||||
"description": "An error popup when we attempted and failed to send a message using endorsements, only for internal users."
|
||||
},
|
||||
"icu:Toast--InvalidStorageServiceHeaders": {
|
||||
"messageformat": "Received invalid response from storage service. Please share your logs.",
|
||||
"description": "[Only shown to internal/beta users] An error popup when we noticed an invalid response (i.e. a web request response) from one of our servers"
|
||||
},
|
||||
"icu:Toast--FailedToImportBackup": {
|
||||
"messageformat": "Failed to process some frames during backup import. Please share your logs.",
|
||||
"description": "[Only shown to internal users] An error popup when we failed to process some parts of a backup import."
|
||||
|
|
|
@ -121,6 +121,8 @@ function getToast(toastType: ToastType): AnyToast {
|
|||
return { toastType: ToastType.GroupLinkCopied };
|
||||
case ToastType.InvalidConversation:
|
||||
return { toastType: ToastType.InvalidConversation };
|
||||
case ToastType.InvalidStorageServiceHeaders:
|
||||
return { toastType: ToastType.InvalidStorageServiceHeaders };
|
||||
case ToastType.LeftGroup:
|
||||
return { toastType: ToastType.LeftGroup };
|
||||
case ToastType.LinkCopied:
|
||||
|
|
|
@ -328,6 +328,20 @@ export function renderToast({
|
|||
);
|
||||
}
|
||||
|
||||
if (toastType === ToastType.InvalidStorageServiceHeaders) {
|
||||
return (
|
||||
<Toast
|
||||
onClose={hideToast}
|
||||
toastAction={{
|
||||
label: i18n('icu:Toast__ActionLabel--SubmitLog'),
|
||||
onClick: onShowDebugLog,
|
||||
}}
|
||||
>
|
||||
{i18n('icu:Toast--InvalidStorageServiceHeaders')}
|
||||
</Toast>
|
||||
);
|
||||
}
|
||||
|
||||
if (toastType === ToastType.FileSaved) {
|
||||
return (
|
||||
<Toast
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import type { RequestInit, Response } from 'node-fetch';
|
||||
import fetch from 'node-fetch';
|
||||
import type { Agent } from 'https';
|
||||
import { escapeRegExp, isNumber, isString, isObject } from 'lodash';
|
||||
import { escapeRegExp, isNumber, isString, isObject, throttle } from 'lodash';
|
||||
import PQueue from 'p-queue';
|
||||
import { v4 as getGuid } from 'uuid';
|
||||
import { z } from 'zod';
|
||||
|
@ -81,6 +81,8 @@ import type {
|
|||
import { isMockServer } from '../util/isMockServer';
|
||||
import { getMockServerPort } from '../util/getMockServerPort';
|
||||
import { pemToDer } from '../util/pemToDer';
|
||||
import { ToastType } from '../types/Toast';
|
||||
import { isProduction } from '../util/version';
|
||||
|
||||
// Note: this will break some code that expects to be able to use err.response when a
|
||||
// web request fails, because it will force it to text. But it is very useful for
|
||||
|
@ -194,6 +196,7 @@ type PromiseAjaxOptionsType = {
|
|||
socketManager?: SocketManager;
|
||||
basicAuth?: string;
|
||||
certificateAuthority?: string;
|
||||
chatServiceUrl?: string;
|
||||
contentType?: string;
|
||||
data?: Uint8Array | (() => Readable) | string;
|
||||
disableRetries?: boolean;
|
||||
|
@ -212,8 +215,8 @@ type PromiseAjaxOptionsType = {
|
|||
| 'byteswithdetails'
|
||||
| 'stream'
|
||||
| 'streamwithdetails';
|
||||
serverUrl?: string;
|
||||
stack?: string;
|
||||
storageUrl?: string;
|
||||
timeout?: number;
|
||||
type: HTTPCodeType;
|
||||
user?: string;
|
||||
|
@ -401,9 +404,35 @@ async function _promiseAjax(
|
|||
throw makeHTTPError('promiseAjax catch', 0, {}, e.toString(), stack);
|
||||
}
|
||||
|
||||
const urlHostname = getHostname(url);
|
||||
|
||||
if (options.storageUrl && url.startsWith(options.storageUrl)) {
|
||||
// The cloud infrastructure that sits in front of the Storage Service / Groups server
|
||||
// has in the past terminated requests with a 403 before they make it to a Signal
|
||||
// server. That's a problem, since we might take destructive action locally in
|
||||
// response to a 403. Responses from a Signal server should always contain the
|
||||
// `x-signal-timestamp` headers.
|
||||
if (response.headers.get('x-signal-timestamp') == null) {
|
||||
log.error(
|
||||
logId,
|
||||
response.status,
|
||||
'Invalid header: missing required x-signal-timestamp header'
|
||||
);
|
||||
|
||||
onIncorrectHeadersFromStorageService();
|
||||
|
||||
// TODO: DESKTOP-8300
|
||||
if (response.status === 403) {
|
||||
throw new Error(
|
||||
`${logId} ${response.status}: Dropping response, missing required x-signal-timestamp header`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
options.serverUrl &&
|
||||
getHostname(options.serverUrl) === getHostname(url)
|
||||
options.chatServiceUrl &&
|
||||
getHostname(options.chatServiceUrl) === urlHostname
|
||||
) {
|
||||
await handleStatusCode(response.status);
|
||||
|
||||
|
@ -2004,6 +2033,7 @@ export function initialize({
|
|||
socketManager: useWebSocketForEndpoint ? socketManager : undefined,
|
||||
basicAuth: param.basicAuth,
|
||||
certificateAuthority,
|
||||
chatServiceUrl,
|
||||
contentType: param.contentType || 'application/json; charset=utf-8',
|
||||
data:
|
||||
param.data ||
|
||||
|
@ -2018,7 +2048,7 @@ export function initialize({
|
|||
type: param.httpType,
|
||||
user: param.username ?? username,
|
||||
redactUrl: param.redactUrl,
|
||||
serverUrl: chatServiceUrl,
|
||||
storageUrl,
|
||||
validateResponse: param.validateResponse,
|
||||
version,
|
||||
unauthenticated: param.unauthenticated,
|
||||
|
@ -4666,3 +4696,16 @@ export function initialize({
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: DESKTOP-8300
|
||||
const onIncorrectHeadersFromStorageService = throttle(
|
||||
() => {
|
||||
if (!isProduction(window.getVersion())) {
|
||||
window.reduxActions.toast.showToast({
|
||||
toastType: ToastType.InvalidStorageServiceHeaders,
|
||||
});
|
||||
}
|
||||
},
|
||||
5 * MINUTE,
|
||||
{ trailing: false }
|
||||
);
|
||||
|
|
|
@ -40,6 +40,7 @@ export enum ToastType {
|
|||
FileSize = 'FileSize',
|
||||
GroupLinkCopied = 'GroupLinkCopied',
|
||||
InvalidConversation = 'InvalidConversation',
|
||||
InvalidStorageServiceHeaders = 'InvalidStorageServiceHeaders',
|
||||
LeftGroup = 'LeftGroup',
|
||||
LinkCopied = 'LinkCopied',
|
||||
LoadingFullLogs = 'LoadingFullLogs',
|
||||
|
@ -133,6 +134,7 @@ export type AnyToast =
|
|||
};
|
||||
}
|
||||
| { toastType: ToastType.InvalidConversation }
|
||||
| { toastType: ToastType.InvalidStorageServiceHeaders }
|
||||
| { toastType: ToastType.LeftGroup }
|
||||
| { toastType: ToastType.LinkCopied }
|
||||
| { toastType: ToastType.LoadingFullLogs }
|
||||
|
|
Loading…
Add table
Reference in a new issue