mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 08:15:17 +00:00
fix(cursor): validate request body on settings endpoints
- Reject null/non-object bodies on PUT /settings with 400 - Validate settings field exists on PUT /settings/raw before write - Use getCcsDir()-based path instead of hardcoded ~/.ccs/ in responses
This commit is contained in:
1 parent
d58e98815b
commit
f5a912b114
1 file changed
+14
-2
@@ -32,6 +32,12 @@ router.put('/', (req: Request, res: Response): void => {
|
|||||||
try {
|
try {
|
||||||
const updates = req.body;
|
const updates = req.body;
|
||||||
|
|
||||||
|
// Reject non-object bodies
|
||||||
|
if (!updates || typeof updates !== 'object' || Array.isArray(updates)) {
|
||||||
|
res.status(400).json({ error: 'Request body must be a JSON object' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Validate input types
|
// Validate input types
|
||||||
if (updates && typeof updates === 'object') {
|
if (updates && typeof updates === 'object') {
|
||||||
if ('port' in updates) {
|
if ('port' in updates) {
|
||||||
@@ -96,7 +102,7 @@ router.get('/raw', (_req: Request, res: Response): void => {
|
|||||||
res.json({
|
res.json({
|
||||||
settings: defaultSettings,
|
settings: defaultSettings,
|
||||||
mtime: Date.now(),
|
mtime: Date.now(),
|
||||||
path: `~/.ccs/cursor.settings.json`,
|
path: settingsPath,
|
||||||
exists: false,
|
exists: false,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@@ -109,7 +115,7 @@ router.get('/raw', (_req: Request, res: Response): void => {
|
|||||||
res.json({
|
res.json({
|
||||||
settings,
|
settings,
|
||||||
mtime: stat.mtimeMs,
|
mtime: stat.mtimeMs,
|
||||||
path: `~/.ccs/cursor.settings.json`,
|
path: settingsPath,
|
||||||
exists: true,
|
exists: true,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -124,6 +130,12 @@ router.get('/raw', (_req: Request, res: Response): void => {
|
|||||||
router.put('/raw', (req: Request, res: Response): void => {
|
router.put('/raw', (req: Request, res: Response): void => {
|
||||||
try {
|
try {
|
||||||
const { settings, expectedMtime } = req.body;
|
const { settings, expectedMtime } = req.body;
|
||||||
|
|
||||||
|
if (!settings || typeof settings !== 'object') {
|
||||||
|
res.status(400).json({ error: 'settings must be a JSON object' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const settingsPath = path.join(getCcsDir(), 'cursor.settings.json');
|
const settingsPath = path.join(getCcsDir(), 'cursor.settings.json');
|
||||||
|
|
||||||
// Check for conflict if file exists and expectedMtime provided
|
// Check for conflict if file exists and expectedMtime provided
|
||||||
|
|||||||
Reference in new issue
Block a user