Skip to content

Fix security vulnerability in default authorization #5

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

Merged
merged 1 commit into from
May 29, 2025
Merged
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
17 changes: 15 additions & 2 deletions src/net/websocket/AuthorizationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,22 @@ export interface AuthorizationProvider<T extends AuthContext = AuthContext> {
}

/**
* A permissive provider that authorises every action. Used as the default so
* existing callers that don't care about auth continue to work unchanged.
* A permissive provider that authorises every action.
* WARNING: This should only be used for development/testing purposes.
* Never use this in production as it allows unrestricted access.
*/
export const allowAll: AuthorizationProvider = {
canAccess: () => true,
};

/**
* A secure default provider that denies all access.
* This forces developers to explicitly implement proper authorization.
* Use this as the default to ensure security by default.
*/
export const denyAll: AuthorizationProvider = {
canAccess: () => {
console.warn('Authorization check failed: No authorization provider configured. Access denied.');
return false;
},
};
6 changes: 3 additions & 3 deletions src/net/websocket/RPCServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Change, EditableVersionMetadata, ListChangesOptions, ListVersionsO
import { StatusError } from '../error.js';
import { JSONRPCServer } from '../protocol/JSONRPCServer.js';
import type { AuthContext, AuthorizationProvider } from './AuthorizationProvider.js';
import { allowAll } from './AuthorizationProvider.js';
import { denyAll } from './AuthorizationProvider.js';

/**
* High-level client for the Patches real-time collaboration service.
Expand All @@ -31,9 +31,9 @@ export class RPCServer {
* @param patches - The patches server instance to handle document operations
* @param history - (Optional) History manager instance to handle versioning operations
* @param branches - (Optional) Branch manager instance to handle branching operations
* @param auth - (Optional) Authorization provider implementation. Defaults to a permissive provider.
* @param auth - (Optional) Authorization provider implementation. Defaults to deny-all for security.
*/
constructor({ patches, history, branches, auth = allowAll }: RPCServerOptions) {
constructor({ patches, history, branches, auth = denyAll }: RPCServerOptions) {
this.rpc = new JSONRPCServer();
this.patches = patches;
this.history = history;
Expand Down
4 changes: 2 additions & 2 deletions src/net/websocket/WebSocketServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ServerTransport } from '../protocol/types.js';
import type { AuthContext, AuthorizationProvider } from './AuthorizationProvider.js';
import { allowAll } from './AuthorizationProvider.js';
import { denyAll } from './AuthorizationProvider.js';
import type { RPCServer } from './RPCServer.js';

/**
Expand All @@ -20,7 +20,7 @@ export class WebSocketServer {
constructor(transport: ServerTransport, rpcServer: RPCServer) {
this.transport = transport;
const { rpc, auth } = rpcServer;
this.auth = auth || allowAll;
this.auth = auth || denyAll;

// Subscription operations
rpc.registerMethod('subscribe', this.subscribe.bind(this));
Expand Down