-
Notifications
You must be signed in to change notification settings - Fork 236
fix: Openai thread IDOR #10806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Openai thread IDOR #10806
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,6 +246,7 @@ export const postMessageToEditHandlersFactory = ( | |
|
|
||
| const threadRelation = await ThreadRelationModel.findOne({ | ||
| threadId: { $eq: threadId }, | ||
| userId: user._id, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 既存の findOne クエリに userId 条件を追加した |
||
| }); | ||
| if (threadRelation == null) { | ||
| return res.apiv3Err(new ErrorV3('ThreadRelation not found'), 404); | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. userId を渡して所有者のスレッドのみ取得するよう変更 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import loginRequiredFactory from '~/server/middlewares/login-required'; | |
| import type { ApiV3Response } from '~/server/routes/apiv3/interfaces/apiv3-response'; | ||
| import loggerFactory from '~/utils/logger'; | ||
|
|
||
| import ThreadRelationModel from '../../models/thread-relation'; | ||
| import { getOpenaiService } from '../../services/openai'; | ||
| import { certifyAiService } from '../middlewares/certify-ai-service'; | ||
|
|
||
|
|
@@ -81,6 +82,14 @@ export const getMessagesFactory = (crowi: Crowi): RequestHandler[] => { | |
| ); | ||
| } | ||
|
|
||
| const threadRelation = await ThreadRelationModel.findOne({ | ||
| threadId: { $eq: threadId }, | ||
| userId: user._id, | ||
| }); | ||
| if (threadRelation == null) { | ||
| return res.apiv3Err(new ErrorV3('Thread not found'), 404); | ||
| } | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ThreadRelationModel.findOne による userId 付きクエリで所有権を確認してからメッセージ取得するよう変更した |
||
| const messages = await openaiService.getMessageData( | ||
| threadId, | ||
| user.lang, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,7 +128,10 @@ export const postMessageHandlersFactory = (crowi: Crowi): RequestHandler[] => { | |
| return res.apiv3Err(new ErrorV3('AI assistant not found'), 404); | ||
| } | ||
|
|
||
| const threadRelation = await ThreadRelationModel.findOne({ threadId }); | ||
| const threadRelation = await ThreadRelationModel.findOne({ | ||
| threadId: { $eq: threadId }, | ||
| userId: user._id, | ||
| }); | ||
|
||
| if (threadRelation == null) { | ||
| return res.apiv3Err(new ErrorV3('ThreadRelation not found'), 404); | ||
| } | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ThreadRelationModel.findOne による userId 付きクエリで所有権を確認してからサービスメソッドを呼び出すよう変更