π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat: consider bearer token in throttler
Pranav C31dec73f3f05
diff --git a/packages/nocodb/src/guards/global/global.guard.ts b/packages/nocodb/src/guards/global/global.guard.tsindex 8e0f944435..0d1ad833fd 100644--- a/packages/nocodb/src/guards/global/global.guard.ts+++ b/packages/nocodb/src/guards/global/global.guard.ts@@ -5,6 +5,7 @@ import { extractRolesObj } from 'nocodb-sdk';import type { Request } from 'express';import type { ExecutionContext } from '@nestjs/common';import { JwtStrategy } from '~/strategies/jwt.strategy';+import { getApiTokenFromAuthHeader } from '~/helpers';@Injectable()export class GlobalGuard extends AuthGuard(['jwt']) {@@ -48,7 +49,10 @@ export class GlobalGuard extends AuthGuard(['jwt']) {if (result) return true;- if (req.headers['xc-token']) {+ if (+ req.headers['xc-token'] ||+ getApiTokenFromAuthHeader(req.headers['authorization'])+ ) {let canActivate = false;try {const guard = new (AuthGuard('authtoken'))(context);diff --git a/packages/nocodb/src/helpers/apiHelpers.ts b/packages/nocodb/src/helpers/apiHelpers.tsindex 1f8ccb0a19..9a18851ebc 100644--- a/packages/nocodb/src/helpers/apiHelpers.ts+++ b/packages/nocodb/src/helpers/apiHelpers.ts@@ -78,3 +78,13 @@ export const validatePayload = (});}};++export const getApiTokenFromAuthHeader = (headerValue?: string) => {+ if (!headerValue) return;++ if (!headerValue.toLowerCase?.()?.startsWith('bearer ')) {+ return;+ }++ return headerValue.substring(7);+};diff --git a/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts b/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.tsindex dc4285dc65..1aed5442cd 100644--- a/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts+++ b/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts@@ -5,6 +5,7 @@ import { Strategy } from 'passport-custom';import type { NcRequest } from '~/interface/config';import { ApiToken, User } from '~/models';import { sanitiseUserObj } from '~/utils';+import { getApiTokenFromAuthHeader } from '~/helpers';@Injectable()export class AuthTokenStrategy extends PassportStrategy(Strategy, 'authtoken') {@@ -12,17 +13,14 @@ export class AuthTokenStrategy extends PassportStrategy(Strategy, 'authtoken') {async validate(req: NcRequest, callback: Function) {try {let user;-+// Extract token from either xc-token header or Authorization Bearer headerlet token = req.headers['xc-token'];-+if (!token && req.headers.authorization) {- const authHeader = req.headers.authorization;- if (authHeader.toLowerCase().startsWith('bearer ')) {- token = authHeader.substring(7); // Remove 'Bearer ' prefix- }+ token = getApiTokenFromAuthHeader(req.headers.authorization);}-+if (token) {const apiToken = await ApiToken.getByToken(token);if (!apiToken) {