mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-10-30 18:51:57 +01:00
Do not let payload search match redacted direct messages (#174)
* Update CONTRIBUTING.md * Update CONTRIBUTING.md * Do not let payload search match redacted direct messages /api/packets shows the text of a direct message (TEXT_MESSAGE_APP to a specific node) as "<redacted>". The contains= filter, however, is a LIKE over the stored packet bytes, which include the decrypted text for messages on a known channel key. With portnum left out of the request, contains=<guess> returned the packet when the guess appeared in a redacted message, so the text could be recovered one substring at a time. Direct text messages are now excluded from the substring match. Broadcast messages and all other packet types search exactly as before. Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com> --------- Co-authored-by: Pablo Revilla <pablorevilla@gmail.com> Co-authored-by: Nathan <nathan@stonekitty.net> Co-authored-by: Claude Mythos 5.1 <noreply@anthropic.com>
This commit is contained in:
1 file changed
+11
@@ -4,11 +4,14 @@ from datetime import datetime, timedelta, timezone
|
||||
from sqlalchemy import Text, and_, cast, func, or_, select
|
||||
from sqlalchemy.orm import lazyload
|
||||
|
||||
from meshtastic.protobuf.portnums_pb2 import PortNum
|
||||
from meshview import database, models
|
||||
from meshview.models import Node, Packet, PacketSeen, Traceroute
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
BROADCAST_NODE_ID = 0xFFFFFFFF
|
||||
|
||||
|
||||
async def get_node(node_id):
|
||||
async with database.async_session() as session:
|
||||
@@ -70,6 +73,14 @@ async def get_packets(
|
||||
contains_lower = f"%{contains.lower()}%"
|
||||
payload_text = cast(models.Packet.payload, Text)
|
||||
conditions.append(func.lower(payload_text).like(contains_lower))
|
||||
# Direct text messages are shown as "<redacted>" by the API, so they must not be
|
||||
# searchable either: a match would reveal their contents one substring at a time.
|
||||
conditions.append(
|
||||
or_(
|
||||
models.Packet.portnum != PortNum.TEXT_MESSAGE_APP,
|
||||
models.Packet.to_node_id == BROADCAST_NODE_ID,
|
||||
)
|
||||
)
|
||||
|
||||
# Apply WHERE conditions
|
||||
if conditions:
|
||||
|
||||
Reference in new issue
Block a user