Security: Validate session ID in NotificationReplyReceiver (#327)
* Security: Validate session ID in NotificationReplyReceiver - Updated `ChatMessageDao.kt` to include `sessionExists` query. - Guarded `NotificationReplyReceiver.kt` `HermesWsClient.sendMessage` execution behind the `dao.sessionExists(sessionId)` check, preventing potential intent injection payloads against inactive/unknown sessions. - Moved message dispatch into DB IO coroutine to ensure safe execution. - Added tests in `NotificationReplyReceiverTest.kt` to assert unknown sessions ignore replies properly. Fixes #268 * Security: Validate session ID in NotificationReplyReceiver - Updated `ChatMessageDao.kt` to include `sessionExists` query. - Guarded `NotificationReplyReceiver.kt` `HermesWsClient.sendMessage` execution behind the `dao.sessionExists(sessionId)` check, preventing potential intent injection payloads against inactive/unknown sessions. - Moved message dispatch into DB IO coroutine and wrapped with a 5s timeout to ensure safe execution. - Added tests in `NotificationReplyReceiverTest.kt` to assert unknown sessions ignore replies properly. Fixes #268 * Security: Validate session ID in NotificationReplyReceiver - Updated `ChatMessageDao.kt` to include `sessionExists` query. - Guarded `NotificationReplyReceiver.kt` `HermesWsClient.sendMessage` execution behind the `dao.sessionExists(sessionId)` check, preventing potential intent injection payloads against inactive/unknown sessions. - Moved message dispatch into DB IO coroutine and wrapped with a 5s timeout to ensure safe execution. - Added tests in `NotificationReplyReceiverTest.kt` to assert unknown sessions ignore replies properly. Fixes #268 * Security: Fix fake token triggering GitGuardian - Replaced high-entropy string `ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890` with obvious fake string `dummy_token_value_that_is_long_enough_to_pass_validation_123` in `ConnectViewModelTest.kt` to fix a false positive alert during GitHub Actions GitGuardian security check. Fixes #268 CI Check failure * Security: Fix fake token triggering GitGuardian and validate session ID - Updated `ChatMessageDao.kt` to include `sessionExists` query. - Guarded `NotificationReplyReceiver.kt` `HermesWsClient.sendMessage` execution behind the `dao.sessionExists(sessionId)` check, preventing potential intent injection payloads against inactive/unknown sessions. - Moved message dispatch into DB IO coroutine and wrapped with a 5s timeout to ensure safe execution. - Added tests in `NotificationReplyReceiverTest.kt` to assert unknown sessions ignore replies properly. - Replaced high-entropy string `ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890` with obvious fake string `dummy_token_value_that_is_long_enough_to_pass_validation_123` in `ConnectViewModelTest.kt` to fix a false positive alert during GitHub Actions GitGuardian security check. Fixes #268 * Security: Fix fake token triggering GitGuardian and validate session ID - Updated `ChatMessageDao.kt` to include `sessionExists` query. - Guarded `NotificationReplyReceiver.kt` `HermesWsClient.sendMessage` execution behind the `dao.sessionExists(sessionId)` check, preventing potential intent injection payloads against inactive/unknown sessions. - Moved message dispatch into DB IO coroutine and wrapped with a 5s timeout to ensure safe execution. - Added tests in `NotificationReplyReceiverTest.kt` to assert unknown sessions ignore replies properly. - Replaced high-entropy string `ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890` with obvious fake string `dummy_token_value_that_is_long_enough_to_pass_validation_123` in `ConnectViewModelTest.kt` to fix a false positive alert during GitHub Actions GitGuardian security check. Fixes #268 * Security: Validate session ID in NotificationReplyReceiver and fix false positive secret - Updated `ChatMessageDao.kt` to include `sessionExists` query. - Guarded `NotificationReplyReceiver.kt` `HermesWsClient.sendMessage` execution behind the `dao.sessionExists(sessionId)` check, preventing potential intent injection payloads against inactive/unknown sessions. - Moved message dispatch into DB IO coroutine and wrapped with a 5s timeout to ensure safe execution. - Added tests in `NotificationReplyReceiverTest.kt` to assert unknown sessions ignore replies properly. - Replaced high-entropy string `ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890` with obvious fake string `dummy_token_value_that_is_long_enough_to_pass_validation_123` in `ConnectViewModelTest.kt` to fix a false positive alert during GitHub Actions GitGuardian security check. Fixes #268 --------- Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
1 parent
d616c56176
commit
3605ca7537
4 files changed
+39
-9
No files matched your search
@@ -48,8 +48,6 @@ open class NotificationReplyReceiver : BroadcastReceiver() {
|
||||
val sessionId = intent.getStringExtra(EXTRA_SESSION_ID)
|
||||
|
||||
if (!replyText.isNullOrBlank() && !sessionId.isNullOrBlank()) {
|
||||
HermesWsClient.sendMessage(sessionId, replyText)
|
||||
|
||||
val pendingResult = goAsyncCompat()
|
||||
kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.IO).launch {
|
||||
try {
|
||||
@@ -58,6 +56,13 @@ open class NotificationReplyReceiver : BroadcastReceiver() {
|
||||
com.m57.hermescontrol.data.local.HermesDatabase
|
||||
.get(context)
|
||||
val dao = db.chatMessageDao()
|
||||
if (!dao.sessionExists(sessionId)) {
|
||||
android.util.Log.w("NotificationReply", "Ignoring reply for unknown session: $sessionId")
|
||||
return@withTimeout
|
||||
}
|
||||
|
||||
HermesWsClient.sendMessage(sessionId, replyText)
|
||||
|
||||
val entity =
|
||||
com.m57.hermescontrol.data.local.ChatMessageEntity(
|
||||
id =
|
||||
@@ -70,18 +75,17 @@ open class NotificationReplyReceiver : BroadcastReceiver() {
|
||||
timestamp = System.currentTimeMillis(),
|
||||
)
|
||||
dao.upsert(entity)
|
||||
|
||||
val repliedNotification = buildReplyNotification(context)
|
||||
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
manager.notify(ChatNotificationService.PENDING_NOTIFICATION_ID, repliedNotification)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("NotificationReply", "Failed to save replied message to Room DB", e)
|
||||
android.util.Log.e("NotificationReply", "Failed to process reply", e)
|
||||
} finally {
|
||||
pendingResult.finish()
|
||||
}
|
||||
}
|
||||
|
||||
val repliedNotification = buildReplyNotification(context)
|
||||
|
||||
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
manager.notify(ChatNotificationService.PENDING_NOTIFICATION_ID, repliedNotification)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user