CVE-2023-34465 (Java, published 2023-06-23T16:15Z)
Description: value: XWiki Platform is a generic wiki platform. Starting in version 11.8-rc-1 and prior to versions 14.4.8, 14.10.6, and 15.2, `Mail.MailConfig` can be edited by any logged-in user by default. Consequently, they can change the mail obfuscation configuration and view and edit the mail sending configuration, including the smtp domain name and credentials. The problem has been patched in XWiki 14.4.8, 14.10.6, and 15.1. As a workaround, the rights of the `Mail.MailConfig` page can be manually updated so that only a set of trusted users can view, edit and delete it (e.g., the `XWiki.XWikiAdminGroup` group).
Severity: nan (CVSS v3 base score: 8.1)
Weakness: CWE-269 \u2014 Improper Privilege Management
The product does not properly assign, modify, track, or check privileges for an actor, creating an unintended sphere of control for that actor.
Repository: https://github.com/xwiki/xwiki-platform
Files changed:
xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authorization/xwiki-platform-security-authorization-bridge/src/main/java/org/xwiki/security/internal/DocumentInitializerRightsManager.java
xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authorization/xwiki-platform-security-authorization-bridge/src/test/java/org/xwiki/security/internal/DocumentInitializerRightsManagerTest.java
Commit message: XWIKI-20671: Fix Mail.MailConfig initialization


Vulnerable code:
import java.util.stream.Collectors;
            updated = initializeRights(document, XWIKI_ADMIN_GROUP_DOCUMENT_REFERENCE, List.of(VIEW, EDIT, DELETE));
    private boolean initializeRights(XWikiDocument document, String xwikiAdminGroupDocumentReference,
        List<Right> rights)
            XWikiContext xwikiContext = this.xcontextProvider.get();
            BaseObject object = document.newXObject(LOCAL_CLASS_REFERENCE, xwikiContext);
            XWikiContext xWikiContext = this.xcontextProvider.get();
            object.set(GROUPS_FIELD_NAME, xwikiAdminGroupDocumentReference, xWikiContext);
            object.set(LEVELS_FIELD_NAME, rights.stream().map(Right::getName).collect(Collectors.toList()),
                xWikiContext);
            object.set(ALLOW_FIELD_NAME, 1, xWikiContext);
        this.document.newXObject(LOCAL_CLASS_REFERENCE, this.xWikiContext);
        assertEquals("view, edit, delete", xObject.getStringValue(LEVELS_FIELD_NAME));

Fixed code:
import org.apache.commons.lang3.StringUtils;
import static java.util.stream.Collectors.joining;
        List<Right> rights = List.of(VIEW, EDIT, DELETE);

        if (fixBadlyInitializedRights(document, rights)) {
            updated = true;
        }

            updated = updated || initializeRights(document, rights);
    private boolean initializeRights(XWikiDocument document, List<Right> rights)
            BaseObject object = document.newXObject(LOCAL_CLASS_REFERENCE, this.xcontextProvider.get());
            setRights(object, rights);

    /**
     * Because of XWIKI-20519, the levels of the rights of {@code XWiki.XWikiAdminGroup} can be badly initialized, and
     * needs to be fixed. This is the case when upgrading from instances running exactly version 14.10.5 or 15.1-rc-1.
     *
     * @param document the document to fix
     * @param rights the rights to set to the {@code XWiki.XWikiAdminGroup} group
     */
    private boolean fixBadlyInitializedRights(XWikiDocument document, List<Right> rights)
    {
        boolean updated = false;
        if (document.getXObjects(LOCAL_CLASS_REFERENCE).size() == 1) {
            BaseObject object = document.getXObject(LOCAL_CLASS_REFERENCE);
            if (StringUtils.isEmpty(object.getStringValue(LEVELS_FIELD_NAME))
                && StringUtils.isEmpty(object.getLargeStringValue(GROUPS_FIELD_NAME)))
            {
                setRights(object, rights);
                updated = true;
            }
        }
        return updated;
    }

    private void setRights(BaseObject object, List<Right> rights)
    {
        object.setLargeStringValue(GROUPS_FIELD_NAME, XWIKI_ADMIN_GROUP_DOCUMENT_REFERENCE);
        object.setStringValue(LEVELS_FIELD_NAME, rights.stream().map(Right::getName).collect(joining(",")));
        object.setIntValue(ALLOW_FIELD_NAME, 1);
    }
        BaseObject baseObject = this.document.newXObject(LOCAL_CLASS_REFERENCE, this.xWikiContext);
        baseObject.setLargeStringValue(LEVELS_FIELD_NAME, "edit");
    @Test
    void restrictToAdminBadlyInitialized() throws Exception
    {
        BaseObject object = this.document.newXObject(LOCAL_CLASS_REFERENCE, this.xWikiContext);
        object.setLargeStringValue(GROUPS_FIELD_NAME, "");
        object.setLargeStringValue(LEVELS_FIELD_NAME, "");
        object.setIntValue(ALLOW_FIELD_NAME, 1);
        assertTrue(this.rightsManager.restrictToAdmin(this.document));
        BaseObject xObject = this.document.getXObject(LOCAL_CLASS_REFERENCE);
        assertEquals("XWiki.XWikiAdminGroup", xObject.getStringValue(GROUPS_FIELD_NAME));
        assertEquals("view,edit,delete", xObject.getStringValue(LEVELS_FIELD_NAME));
        assertEquals("1", xObject.getStringValue(ALLOW_FIELD_NAME));
    }

        assertEquals("view,edit,delete", xObject.getStringValue(LEVELS_FIELD_NAME));