CVE-2023-37911 (Java, published 2023-10-25T18:17Z)
Description: value: XWiki Platform is a generic wiki platform offering runtime services for applications built on top of it. Starting in version 9.4-rc-1 and prior to versions 14.10.8 and 15.3-rc-1, when a document has been deleted and re-created, it is possible for users with view right on the re-created document but not on the deleted document to view the contents of the deleted document. Such a situation might arise when rights were added to the deleted document. This can be exploited through the diff feature and, partially, through the REST API by using versions such as `deleted:1` (where the number counts the deletions in the wiki and is thus guessable). Given sufficient rights, the attacker can also re-create the deleted document, thus extending the scope to any deleted document as long as the attacker has edit right in the location of the deleted document. This vulnerability has been patched in XWiki 14.10.8 and 15.3 RC1 by properly checking rights when deleted revisions of a document are accessed. The only workaround is to regularly clean deleted documents to minimize the potential exposure. Extra care should be taken when deleting sensitive documents that are protected individually (and not, e.g., by being placed in a protected space) or deleting a protected space as a whole.
Severity: nan (CVSS v3 base score: 6.5)
Weakness: CWE-668 \u2014 Exposure of Resource to Wrong Sphere
The product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource.
Repository: https://github.com/xwiki/xwiki-platform
Files changed:
xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/Document.java
xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/XWiki.java
xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/api/DocumentTest.java
xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/api/XWikiTest.java
Commit message: XWIKI-20685: Check access on the revision provider in the script API


Vulnerable code:
     * @return the document corresponding to the requested revision or {@code null} if the revision does not exist.
            XWikiDocument documentRevision = getDocumentRevisionProvider().getRevision(this.doc, revision);

            return null;
                XWikiDocument documentRevision = getDocumentRevisionProvider().getRevision(reference, revision);
        this.apiDocument =
            new Document(new XWikiDocument(new DocumentReference("xwiki", "MilkyWay", "Fidis")), xWikiContext);

Fixed code:
import org.apache.commons.lang.exception.ExceptionUtils;
import org.xwiki.security.authorization.AuthorizationException;
     * @return the document corresponding to the requested revision or {@code null} if the revision does not exist or
     * access is denied.
            DocumentRevisionProvider revisionProvider = getDocumentRevisionProvider();
            revisionProvider.checkAccess(Right.VIEW, CurrentUserReference.INSTANCE, getDocumentReference(), revision);
            XWikiDocument documentRevision = revisionProvider.getRevision(this.doc, revision);
        } catch (AuthorizationException e) {
            LOGGER.info("Access denied for loading revision [{}] of document [{}]: [{}]", revision,
                getDocumentReferenceWithLocale(), ExceptionUtils.getRootCauseMessage(e));

        return null;
import org.xwiki.security.authorization.AuthorizationException;
import org.xwiki.user.CurrentUserReference;
                DocumentRevisionProvider revisionProvider = getDocumentRevisionProvider();
                revisionProvider.checkAccess(Right.VIEW, CurrentUserReference.INSTANCE, reference, revision);
                XWikiDocument documentRevision = revisionProvider.getRevision(reference, revision);
        } catch (AuthorizationException e) {
            LOGGER.info("Access denied for loading revision [{}] of document [{}]: [{}]", revision, reference,
                ExceptionUtils.getRootCauseMessage(e));
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.xwiki.security.authorization.AuthorizationException;
import org.xwiki.test.LogLevel;
import org.xwiki.test.junit5.LogCaptureExtension;
import com.xpn.xwiki.doc.DocumentRevisionProvider;
import static org.mockito.Mockito.doThrow;
    @RegisterExtension
    private LogCaptureExtension logCapture = new LogCaptureExtension(LogLevel.INFO);


    @ParameterizedTest
    @ValueSource(booleans = { false, true })
    void getDocumentRevision(boolean allowAccess, MockitoComponentManager componentManager) throws Exception
    {
        DocumentReference documentReference = new DocumentReference("Wiki", "Space", "Page");
        XWikiDocument xWikiDocument = new XWikiDocument(documentReference);
        Document document = new Document(xWikiDocument, this.oldcore.getXWikiContext());
        DocumentRevisionProvider revisionProvider =
            componentManager.registerMockComponent(DocumentRevisionProvider.class);
        String revision = "42.1";
        XWikiDocument revisionDocument = mock(XWikiDocument.class);
        when(revisionProvider.getRevision(xWikiDocument, revision)).thenReturn(revisionDocument);
        String deniedMessage = "Denied";
        if (!allowAccess) {
            doThrow(new AuthorizationException(deniedMessage)).when(revisionProvider)
                .checkAccess(Right.VIEW, CurrentUserReference.INSTANCE, documentReference, revision);
            assertNull(document.getDocumentRevision(revision));
            assertEquals(1, this.logCapture.size());
            assertEquals(String.format("Access denied for loading revision [%s] of document [%s()]: "
                    + "[AuthorizationException: %s]", revision,
                documentReference, deniedMessage), this.logCapture.getMessage(0));
        } else {
            assertEquals(new Document(revisionDocument, this.oldcore.getXWikiContext()),
                document.getDocumentRevision(revision));
        }
        verify(revisionProvider).checkAccess(Right.VIEW, CurrentUserReference.INSTANCE, documentReference, revision);
    }
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.xwiki.security.authorization.AuthorizationException;
import org.xwiki.security.authorization.ContextualAuthorizationManager;
import org.xwiki.security.authorization.Right;
import com.xpn.xwiki.doc.DocumentRevisionProvider;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
    private static final DocumentReference DOCUMENT_REFERENCE = new DocumentReference("xwiki", "MilkyWay", "Fidis");

        this.apiDocument = new Document(new XWikiDocument(DOCUMENT_REFERENCE), xWikiContext);

    @ParameterizedTest
    @ValueSource(booleans = { false, true })
    void getDocumentRevision(boolean allowAccess, MockitoOldcore mockitoOldcore) throws Exception
    {
        DocumentRevisionProvider revisionProvider =
            mockitoOldcore.getMocker().registerMockComponent(DocumentRevisionProvider.class);
        ContextualAuthorizationManager contextualAuthorizationManager =
            mockitoOldcore.getMockContextualAuthorizationManager();

        XWikiDocument deletedDocument = new XWikiDocument(DOCUMENT_REFERENCE);
        deletedDocument.setContent("Deleted");
        String revision = "deleted:1";
        when(revisionProvider.getRevision(DOCUMENT_REFERENCE, revision)).thenReturn(deletedDocument);

        when(contextualAuthorizationManager.hasAccess(Right.VIEW, DOCUMENT_REFERENCE)).thenReturn(true);

        if (!allowAccess) {
            doThrow(new AuthorizationException("Denied")).when(revisionProvider)
                .checkAccess(Right.VIEW, CurrentUserReference.INSTANCE, DOCUMENT_REFERENCE, revision);
            assertNull(this.apiXWiki.getDocument(DOCUMENT_REFERENCE, revision));
        } else {
            assertEquals(new Document(deletedDocument, mockitoOldcore.getXWikiContext()),
                this.apiXWiki.getDocument(DOCUMENT_REFERENCE, revision));
        }

        verify(revisionProvider, times(allowAccess ? 1 : 0)).getRevision(DOCUMENT_REFERENCE, revision);
        verify(revisionProvider).checkAccess(Right.VIEW, CurrentUserReference.INSTANCE, DOCUMENT_REFERENCE, revision);
        verify(contextualAuthorizationManager).hasAccess(Right.VIEW, DOCUMENT_REFERENCE);
    }