From 7a01c43a57270fd972f324adbc85091ab8a22410 Mon Sep 17 00:00:00 2001 From: "Schimon Jehudah, Adv." Date: Tue, 22 Oct 2024 17:34:07 +0300 Subject: [PATCH] Python : Fix data retrieval from group chat. --- fasi.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/fasi.py b/fasi.py index 45597c9..74f63e9 100644 --- a/fasi.py +++ b/fasi.py @@ -101,6 +101,9 @@ class HttpInstance: jid_bare = jid note = 'Jabber ID appears to be malformed' + if jid_bare == jabber_id: + raise HTTPException(status_code=403, detail='access-denied') + #try: if True: exception = jid_vcard = messages_10 = note = node_title = \ @@ -224,6 +227,9 @@ class HttpInstance: jid_bare = jid note = 'Jabber ID appears to be malformed' + if jid_bare == jabber_id: + raise HTTPException(status_code=403, detail='access-denied') + #try: if True: entries = [] @@ -401,6 +407,9 @@ class HttpInstance: jid_bare = jid note = 'Jabber ID appears to be malformed' + if jid_bare == jabber_id: + raise HTTPException(status_code=403, detail='access-denied') + #try: if True: exception = note = selection = services_sorted = None @@ -526,6 +535,9 @@ class HttpInstance: jid_bare = jid note = 'Jabber ID appears to be malformed' + if jid_bare == jabber_id: + raise HTTPException(status_code=403, detail='access-denied') + #try: if True: action = count = exception = instance = jid_vcard = \ @@ -707,6 +719,12 @@ class HttpInstance: response.headers['Content-Type'] = 'application/xhtml+xml' return response + @self.app.exception_handler(403) + def not_found_exception_handler(request: Request, exc: HTTPException): + action = 'Warning' + title = 'Access Denied' + return result_get(request, action, title) + @self.app.exception_handler(404) def not_found_exception_handler(request: Request, exc: HTTPException): action = 'Warning' @@ -886,8 +904,8 @@ class FileUtilities: # TODO Create configurations for group chat preview room_info_muc = await XmppXep0045.get_room_information( xmpp_instance, jid_bare, alias, maxstanzas=50) - # NOTE Don not mix error messages with node titles and descriptions etc. - if isinstance(room_info_muc['iq'], stanza.iq.Iq): + # NOTE Do not mix error messages with node titles and descriptions etc. + if isinstance(room_info_muc['iq'], tuple): iq = room_info_muc['iq'] for message in iq[3]: messages.append({ @@ -1427,7 +1445,7 @@ class XmppXep0045: #presence_options = {"pfrom" : jid_from}, #seconds=seconds, #since=since, - timeout=5 + timeout=10 ) except TimeoutError as e: #raise HTTPException(status_code=504, detail='request-timeout-reached')