log client id on sdk auth error
This commit is contained in:
@@ -13,6 +13,27 @@ const cleanDomain = (domain: string) =>
|
|||||||
.replace(/https?:\/\//, '')
|
.replace(/https?:\/\//, '')
|
||||||
.replace(/\/$/, '');
|
.replace(/\/$/, '');
|
||||||
|
|
||||||
|
class SdkAuthError extends Error {
|
||||||
|
payload: {
|
||||||
|
clientId?: string;
|
||||||
|
clientSecret?: string;
|
||||||
|
origin?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
message: string,
|
||||||
|
payload: {
|
||||||
|
clientId?: string;
|
||||||
|
clientSecret?: string;
|
||||||
|
origin?: string;
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
super(message);
|
||||||
|
this.name = 'SdkAuthError';
|
||||||
|
this.payload = payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function validateSdkRequest(
|
export async function validateSdkRequest(
|
||||||
headers: RawRequestDefaultExpression['headers']
|
headers: RawRequestDefaultExpression['headers']
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
@@ -22,11 +43,20 @@ export async function validateSdkRequest(
|
|||||||
const clientSecretOld = headers['mixan-client-secret'] as string;
|
const clientSecretOld = headers['mixan-client-secret'] as string;
|
||||||
const clientId = clientIdNew || clientIdOld;
|
const clientId = clientIdNew || clientIdOld;
|
||||||
const clientSecret = clientSecretNew || clientSecretOld;
|
const clientSecret = clientSecretNew || clientSecretOld;
|
||||||
|
|
||||||
const origin = headers.origin;
|
const origin = headers.origin;
|
||||||
|
|
||||||
|
const createError = (message: string) =>
|
||||||
|
new SdkAuthError(message, {
|
||||||
|
clientId,
|
||||||
|
clientSecret:
|
||||||
|
typeof clientSecret === 'string'
|
||||||
|
? clientSecret.slice(0, 5) + '...' + clientSecret.slice(-5)
|
||||||
|
: 'none',
|
||||||
|
origin,
|
||||||
|
});
|
||||||
|
|
||||||
if (!clientId) {
|
if (!clientId) {
|
||||||
throw new Error('Ingestion: Missing client id');
|
throw createError('Ingestion: Missing client id');
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = await db.client
|
const client = await db.client
|
||||||
@@ -38,11 +68,11 @@ export async function validateSdkRequest(
|
|||||||
.catch(() => null);
|
.catch(() => null);
|
||||||
|
|
||||||
if (!client) {
|
if (!client) {
|
||||||
throw new Error('Ingestion: Invalid client id');
|
throw createError('Ingestion: Invalid client id');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!client.projectId) {
|
if (!client.projectId) {
|
||||||
throw new Error('Ingestion: Client has no project');
|
throw createError('Ingestion: Client has no project');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.cors) {
|
if (client.cors) {
|
||||||
@@ -67,12 +97,7 @@ export async function validateSdkRequest(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error({
|
throw createError('Ingestion: Invalid cors or secret');
|
||||||
client,
|
|
||||||
headers,
|
|
||||||
origin,
|
|
||||||
});
|
|
||||||
throw new Error('Ingestion: Invalid cors or secret');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function validateExportRequest(
|
export async function validateExportRequest(
|
||||||
|
|||||||
Reference in New Issue
Block a user