@radnine/claude-session-daemon 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/config.js +2 -2
- package/src/connections/standalone-server.js +33 -19
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -16,8 +16,8 @@ function loadConfig() {
|
|
|
16
16
|
const env = process.env;
|
|
17
17
|
|
|
18
18
|
const config = {
|
|
19
|
-
// Operating mode: '
|
|
20
|
-
mode: env.CLAUDE_DAEMON_MODE || '
|
|
19
|
+
// Operating mode: 'standalone' runs own WS server, 'actioncable' connects to Rails
|
|
20
|
+
mode: env.CLAUDE_DAEMON_MODE || 'standalone',
|
|
21
21
|
|
|
22
22
|
// Working directory for Claude CLI processes
|
|
23
23
|
workingDir: env.CLAUDE_WORKING_DIR || process.cwd(),
|
|
@@ -148,35 +148,49 @@ class StandaloneServer extends BaseConnection {
|
|
|
148
148
|
// ---------------------------------------------------------------------------
|
|
149
149
|
|
|
150
150
|
_handleConnection(ws, req) {
|
|
151
|
-
|
|
152
|
-
let token = null;
|
|
153
|
-
try {
|
|
154
|
-
const url = new URL(req.url, `http://localhost:${this.port}`);
|
|
155
|
-
token = url.searchParams.get('token');
|
|
156
|
-
} catch (_) {
|
|
157
|
-
// If URL parsing fails, token stays null
|
|
158
|
-
}
|
|
151
|
+
const isLocalhost = this._isLocalhostConnection(req);
|
|
159
152
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
153
|
+
// Validate auth token from query param (skip for localhost)
|
|
154
|
+
if (!isLocalhost) {
|
|
155
|
+
let token = null;
|
|
156
|
+
try {
|
|
157
|
+
const url = new URL(req.url, `http://localhost:${this.port}`);
|
|
158
|
+
token = url.searchParams.get('token');
|
|
159
|
+
} catch (_) {
|
|
160
|
+
// If URL parsing fails, token stays null
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (token !== this._token) {
|
|
164
|
+
this._sendToClient(ws, {
|
|
165
|
+
type: 'error',
|
|
166
|
+
code: 'AUTH_FAILED',
|
|
167
|
+
message: 'Invalid or missing auth token',
|
|
168
|
+
timestamp: Date.now(),
|
|
169
|
+
});
|
|
170
|
+
ws.close(4001, 'Authentication failed');
|
|
171
|
+
this._logger.warn('Connection rejected: invalid auth token');
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
170
174
|
}
|
|
171
175
|
|
|
172
176
|
// Track the authenticated client
|
|
173
177
|
this._clients.set(ws, { authenticated: true });
|
|
174
|
-
this._logger.info('Client connected');
|
|
178
|
+
this._logger.info('Client connected', { localhost: isLocalhost });
|
|
175
179
|
|
|
176
180
|
ws.on('message', (raw) => this._handleMessage(ws, raw));
|
|
177
181
|
ws.on('close', () => this._handleDisconnect(ws));
|
|
178
182
|
}
|
|
179
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Check if the connection originates from localhost.
|
|
186
|
+
* @param {import('http').IncomingMessage} req
|
|
187
|
+
* @returns {boolean}
|
|
188
|
+
*/
|
|
189
|
+
_isLocalhostConnection(req) {
|
|
190
|
+
const addr = req.socket.remoteAddress;
|
|
191
|
+
return addr === '127.0.0.1' || addr === '::1' || addr === '::ffff:127.0.0.1';
|
|
192
|
+
}
|
|
193
|
+
|
|
180
194
|
_handleMessage(ws, raw) {
|
|
181
195
|
let msg;
|
|
182
196
|
try {
|