fix(cursor): address PR #528 review feedback

- Replace non-null assertions with guard clauses in cursor-routes.ts
- Add port range validation (1-65535) in cursor-settings-routes.ts
This commit is contained in:
Tam Nhu Tran committed 2026-02-12 03:58:23 +07:00
1 parent 55bc53152c
commit d58e98815b
2 files changed
+13 -7

No files matched your search

+4 -4
View File
@@ -121,15 +121,15 @@ router.post('/auth/auto-detect', async (_req: Request, res: Response): Promise<v
try { try {
const result = autoDetectTokens(); const result = autoDetectTokens();
if (!result.found) { if (!result.found || !result.accessToken || !result.machineId) {
res.status(404).json({ error: result.error }); res.status(404).json({ error: result.error ?? 'Token not found' });
return; return;
} }
// Save credentials // Save credentials
saveCredentials({ saveCredentials({
accessToken: result.accessToken!, accessToken: result.accessToken,
machineId: result.machineId!, machineId: result.machineId,
authMethod: 'auto-detect', authMethod: 'auto-detect',
importedAt: new Date().toISOString(), importedAt: new Date().toISOString(),
}); });
@@ -34,9 +34,15 @@ router.put('/', (req: Request, res: Response): void => {
// Validate input types // Validate input types
if (updates && typeof updates === 'object') { if (updates && typeof updates === 'object') {
if ('port' in updates && typeof updates.port !== 'number') { if ('port' in updates) {
res.status(400).json({ error: 'port must be a number' }); if (typeof updates.port !== 'number' || !Number.isInteger(updates.port)) {
return; res.status(400).json({ error: 'port must be an integer' });
return;
}
if (updates.port < 1 || updates.port > 65535) {
res.status(400).json({ error: 'port must be between 1 and 65535' });
return;
}
} }
if ('auto_start' in updates && typeof updates.auto_start !== 'boolean') { if ('auto_start' in updates && typeof updates.auto_start !== 'boolean') {
res.status(400).json({ error: 'auto_start must be a boolean' }); res.status(400).json({ error: 'auto_start must be a boolean' });