Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: localhost for mcp

Nevo David0d8d0f228564
diff --git a/.env.example b/.env.example
index 4211d67ca..f8c783247 100644
--- a/.env.example
+++ b/.env.example
@@ -106,9 +106,11 @@ OPENAI_OAUTH_CLIENT_ID=""
# MCP OAuth Dynamic Client Registration (RFC 7591) redirect-domain allowlist.
# When set (comma separated), POST /oauth/register only accepts redirect_uris
# whose host matches a listed domain or one of its subdomains; unset or empty
-# means any client can self-register. Example locks DCR to the claude.ai
-# connector (note: also blocks localhost callbacks, e.g. Claude Code -
-# those clients can use the API-key /mcp/:id endpoints instead).
+# means any client can self-register. Only https callbacks are checked:
+# loopback (http://localhost:8787/callback - Grok, Claude Code) and
+# private-use scheme callbacks (cursor://...) stay on the user's machine
+# and are always accepted. Example locks web callbacks to the claude.ai
+# connector; add cursor.com for Cursor.
# DCR_VERIFIED_DOMAINS="claude.ai,claude.com"
NEXT_PUBLIC_DISCORD_SUPPORT=""
NEXT_PUBLIC_POLOTNO=""
diff --git a/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.ts b/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.ts
index ea18333f7..5c4e20b98 100644
--- a/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/oauth/oauth.service.ts
@@ -20,6 +20,17 @@ const oauthScope = (clientId: string) =>
'mcp:write',
].join(' ');
+// Schemes a browser would execute instead of navigating away from the
+// consent screen, so they can never be a redirect_uri
+const browserSchemes = [
+ 'javascript:',
+ 'data:',
+ 'blob:',
+ 'file:',
+ 'vbscript:',
+ 'about:',
+];
+
@Injectable()
export class OAuthService {
constructor(private _oauthRepository: OAuthRepository) {}
@@ -99,6 +110,7 @@ export class OAuthService {
async registerDynamicClient(dto: RegisterClientDto) {
const redirectUris = dto.redirect_uris.map((uri) => uri.trim());
+ const verifiedDomains = this.verifiedDomainList();
for (const uri of redirectUris) {
let parsed: URL;
try {
@@ -109,31 +121,48 @@ export class OAuthService {
HttpStatus.BAD_REQUEST
);
}
- const isLoopback = ['localhost', '127.0.0.1', '[::1]'].includes(parsed.hostname);
- if (parsed.protocol !== 'https:' && !isLoopback) {
+
+ // The consent screen navigates to the redirect_uri, so schemes the
+ // browser would execute in our origin can never be a callback
+ if (browserSchemes.includes(parsed.protocol)) {
throw new HttpException(
- { error: 'invalid_redirect_uri', error_description: 'redirect_uris must use https (http is allowed for loopback only)' },
+ { error: 'invalid_redirect_uri', error_description: `redirect_uri scheme "${parsed.protocol}" is not allowed` },
HttpStatus.BAD_REQUEST
);
}
- }
- const verifiedDomains = this.verifiedDomainList();
- if (verifiedDomains.length) {
- for (const uri of redirectUris) {
- const host = new URL(uri).hostname.toLowerCase();
- const isVerified = verifiedDomains.some(
- (domain) => host === domain || host.endsWith('.' + domain)
+ const isLoopback =
+ parsed.protocol === 'http:' &&
+ ['localhost', '127.0.0.1', '[::1]'].includes(parsed.hostname);
+ // Private-use schemes (RFC 8252 Β§7.1), e.g.
+ // cursor://anysphere.cursor-mcp/oauth/callback
+ const isPrivateScheme = !['http:', 'https:'].includes(parsed.protocol);
+ if (parsed.protocol === 'http:' && !isLoopback) {
+ throw new HttpException(
+ { error: 'invalid_redirect_uri', error_description: 'redirect_uris must use https or a private-use scheme (http is allowed for loopback only)' },
+ HttpStatus.BAD_REQUEST
+ );
+ }
+
+ // Loopback and private-use callbacks never leave the user's machine
+ // (native clients like Cursor, Grok and Claude Code), so only web
+ // callbacks are held to the verified domain list
+ if (isLoopback || isPrivateScheme || !verifiedDomains.length) {
+ continue;
+ }
+
+ const host = parsed.hostname.toLowerCase();
+ const isVerified = verifiedDomains.some(
+ (domain) => host === domain || host.endsWith('.' + domain)
+ );
+ if (!isVerified) {
+ throw new HttpException(
+ {
+ error: 'invalid_redirect_uri',
+ error_description: `redirect_uri host "${host}" is not a verified domain`,
+ },
+ HttpStatus.BAD_REQUEST
);
- if (!isVerified) {
- throw new HttpException(
- {
- error: 'invalid_redirect_uri',
- error_description: `redirect_uri host "${host}" is not a verified domain`,
- },
- HttpStatus.BAD_REQUEST
- );
- }
}
}
diff --git a/libraries/nestjs-libraries/src/dtos/oauth/register-client.dto.ts b/libraries/nestjs-libraries/src/dtos/oauth/register-client.dto.ts
index 6ee2defe2..fa41de1a2 100644
--- a/libraries/nestjs-libraries/src/dtos/oauth/register-client.dto.ts
+++ b/libraries/nestjs-libraries/src/dtos/oauth/register-client.dto.ts
@@ -4,16 +4,14 @@ import {
IsDefined,
IsOptional,
IsString,
- IsUrl,
} from 'class-validator';
export class RegisterClientDto {
+ // https, http loopback or a private-use scheme (cursor://...),
+ // validated in OAuthService.registerDynamicClient
@IsArray()
@ArrayNotEmpty()
- @IsUrl(
- { require_tld: false, require_protocol: true, protocols: ['http', 'https'] },
- { each: true }
- )
+ @IsString({ each: true })
@IsDefined()
redirect_uris: string[];