@radnine/claude-session-daemon 0.1.1 → 0.2.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radnine/claude-session-daemon",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Node.js daemon for managing Claude CLI sessions",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -148,35 +148,49 @@ class StandaloneServer extends BaseConnection {
148
148
  // ---------------------------------------------------------------------------
149
149
 
150
150
  _handleConnection(ws, req) {
151
- // Validate auth token from query param
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
- if (token !== this._token) {
161
- this._sendToClient(ws, {
162
- type: 'error',
163
- code: 'AUTH_FAILED',
164
- message: 'Invalid or missing auth token',
165
- timestamp: Date.now(),
166
- });
167
- ws.close(4001, 'Authentication failed');
168
- this._logger.warn('Connection rejected: invalid auth token');
169
- return;
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 {