view libervia/web/pages/forums/list/page_meta.py @ 1598:86c7a3a625d5

server: always start a new session on connection: The session was kept when a user was connecting from service profile (but not from other profiles), this was leading to session fixation vulnerability (an attacker on the same machine could get service profile session cookie, and use it when a victim would log-in). This patch fixes it by always starting a new session on connection. fix 443
author Goffi <goffi@goffi.org>
date Fri, 23 Feb 2024 13:35:24 +0100
parents eb00d593801d
children
line wrap: on
line source

#!/usr/bin/env python3

from libervia.web.server.constants import Const as C
from libervia.backend.core.log import getLogger
from libervia.backend.core.i18n import _
from libervia.backend.tools.common import uri as xmpp_uri

log = getLogger(__name__)
import json

"""forum handling pages"""

name = "forums"
access = C.PAGES_ACCESS_PUBLIC
template = "forum/overview.html"


def parse_url(self, request):
    self.get_path_args(
        request,
        ["service", "node", "forum_key"],
        service="@jid",
        node="@",
        forum_key="",
    )


def add_breadcrumb(self, request, breadcrumbs):
    # we don't want breadcrumbs here as long as there is no forum discovery
    # because it will be the landing page for forums activity until then
    pass


def get_links(self, forums):
    for forum in forums:
        try:
            uri = forum["uri"]
        except KeyError:
            pass
        else:
            uri = xmpp_uri.parse_xmpp_uri(uri)
            service = uri["path"]
            node = uri["node"]
            forum["http_url"] = self.get_page_by_name("forum_topics").get_url(service, node)
        if "sub-forums" in forum:
            get_links(self, forum["sub-forums"])


async def prepare_render(self, request):
    data = self.get_r_data(request)
    template_data = request.template_data
    service, node, key = data["service"], data["node"], data["forum_key"]
    profile = self.get_profile(request) or C.SERVICE_PROFILE

    try:
        forums_raw = await self.host.bridge_call(
            "forums_get", service.full() if service else "", node, key, profile
        )
    except Exception as e:
        log.warning(_("Can't retrieve forums: {msg}").format(msg=e))
        forums = []
    else:
        forums = json.loads(forums_raw)
    get_links(self, forums)

    template_data["forums"] = forums