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

Remove Auth headers when calling rooms endpoint #3249

Open
wants to merge 1 commit into
base: unstable
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
3 changes: 2 additions & 1 deletion ts/session/apis/open_group_api/sogsv3/sogsV3RoomInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { OpenGroupV2Room } from '../../../../data/types';

export const getAllRoomInfos = async (roomInfos: OpenGroupV2Room) => {
const result = await OnionSending.sendJsonViaOnionV4ToSogs({
blinded: true,
blinded: false,
endpoint: '/rooms',
method: 'GET',
serverPubkey: roomInfos.serverPublicKey,
Expand All @@ -18,6 +18,7 @@ export const getAllRoomInfos = async (roomInfos: OpenGroupV2Room) => {
serverUrl: roomInfos.serverUrl,
headers: null,
throwErrors: false,
includeAuthHeaders: false, // Don't include headers in default room requests (excessive metadata)
});

// not a batch call yet as we need to exclude headers for this call for now
Expand Down
32 changes: 22 additions & 10 deletions ts/session/onions/onionSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ async function sendJsonViaOnionV4ToSogs(sendOptions: {
abortSignal: AbortSignal;
headers: Record<string, any> | null;
throwErrors: boolean;
includeAuthHeaders?: boolean;
}): Promise<OnionV4JSONSnodeResponse | null> {
const {
serverUrl,
Expand All @@ -288,23 +289,34 @@ async function sendJsonViaOnionV4ToSogs(sendOptions: {
abortSignal,
headers: includedHeaders,
throwErrors,
includeAuthHeaders = true, // Default to true
} = sendOptions;

if (!endpoint.startsWith('/')) {
throw new Error('endpoint needs a leading /');
}

const builtUrl = new URL(`${serverUrl}${endpoint}`);
let headersWithSogsHeadersIfNeeded = await OpenGroupPollingUtils.getOurOpenGroupHeaders(
serverPubkey,
endpoint,
method,
blinded,
stringifiedBody
);
let headersWithSogsHeadersIfNeeded: Record<string, any> = includedHeaders || {};

if (!headersWithSogsHeadersIfNeeded) {
return null;
if (includeAuthHeaders) {
const ourHeaders = await OpenGroupPollingUtils.getOurOpenGroupHeaders(
serverPubkey,
endpoint,
method,
blinded,
stringifiedBody
);

if (!ourHeaders) {
return null;
}

headersWithSogsHeadersIfNeeded = {
...headersWithSogsHeadersIfNeeded,
...ourHeaders,
};
}
headersWithSogsHeadersIfNeeded = { ...includedHeaders, ...headersWithSogsHeadersIfNeeded };

const res = await OnionSending.sendViaOnionV4ToNonSnodeWithRetries(
serverPubkey,
Expand Down
Loading