fix(security): IDOR — PUT/DELETE /api/offices/:id теперь проверяет ownership#18
Merged
Conversation
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Закрывает уязвимость, упомянутую в Notes PR #15:
Было:
PUT /api/offices/:officeIdиDELETE /api/offices/:officeIdпринимали запрос от любого авторизованного пользователя — стоило только знать ID чужого офиса, и можно было его переименовать или удалить. Это IDOR (Insecure Direct Object Reference).Стало: оба endpoint'а вызывают
isOfficeOwner(req.user, officeId)— проверкаoffices.owner_id === req.user.id(или системная рольowner). Если не владелец →403 Доступ запрещён.Изменения
server/controllers/officeController.js:isOfficeOwner(user, officeId)— селектитowner_idиз БД и сравнивает сreq.user.id.updateOffice— добавлен guard перед записью.deleteOffice— добавлен guard перед удалением.Тесты
server/__tests__/offices.test.js, +3 теста:PUT /api/offices/:id— чужак (другой директор) пытается обновить — 403, и реально в БД имя не поменялось.DELETE /api/offices/:id— владелец удаляет свой офис → 2xx, строка изofficesисчезает.DELETE /api/offices/:id— чужак удаляет → 403, строка в БД на месте.Полный backend Jest suite: 95/95 PASS.
Review & Testing Checklist for Human
officeIdприходит403.Notes
— Хелпер
isOfficeOwnerлокальный дляofficeController.js. Если в будущем понадобится использовать его ещё где-то (например, для трансфера офиса, изменения плана и т.п.), можно вынести вutils/ensureOffice.js.— Системная роль
'owner'(если она когда-то будет назначена админу всей системы) проходит проверку без БД-запроса.— Этот PR не меняет права на GET (чтение) — там уже работает
checkOfficeAccess.Link to Devin session: https://app.devin.ai/sessions/514f368ad0194bf18d0327e62a88aeda
Requested by: @Br1Im