VYPR
Moderate severityNVD Advisory· Published Jul 31, 2024· Updated Jul 31, 2024

XWiki Platform vulnerable to document deletion and overwrite from edit

CVE-2024-37898

Description

XWiki Platform is a generic wiki platform offering runtime services for applications built on top of it. When a user has view but not edit right on a page in XWiki, that user can delete the page and replace it by a page with new content without having delete right. The previous version of the page is moved into the recycle bin and can be restored from there by an admin. As the user is recorded as deleter, the user would in theory also be able to view the deleted content, but this is not directly possible as rights of the previous version are transferred to the new page and thus the user still doesn't have view right on the page. It therefore doesn't seem to be possible to exploit this to gain any rights. This has been patched in XWiki 14.10.21, 15.5.5 and 15.10.6 by cancelling save operations by users when a new document shall be saved despite the document's existing already.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
org.xwiki.platform:xwiki-platform-oldcoreMaven
>= 13.10.4, < 14.10.2114.10.21
org.xwiki.platform:xwiki-platform-oldcoreMaven
>= 14.2, < 14.10.2114.10.21
org.xwiki.platform:xwiki-platform-oldcoreMaven
>= 15.0, < 15.5.515.5.5
org.xwiki.platform:xwiki-platform-oldcoreMaven
>= 15.6-rc-1, < 15.10.615.10.6

Affected products

1

Patches

4
e4968fe268e5

XWIKI-21553: Do not override existing documents on user action (#2790)

https://github.com/xwiki/xwiki-platformMichael HamannJan 16, 2024via ghsa
3 files changed · +164 0
  • xwiki-platform-core/xwiki-platform-oldcore/src/main/java/org/xwiki/internal/document/DocumentOverrideListener.java+77 0 added
    @@ -0,0 +1,77 @@
    +/*
    + * See the NOTICE file distributed with this work for additional
    + * information regarding copyright ownership.
    + *
    + * This is free software; you can redistribute it and/or modify it
    + * under the terms of the GNU Lesser General Public License as
    + * published by the Free Software Foundation; either version 2.1 of
    + * the License, or (at your option) any later version.
    + *
    + * This software is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    + * Lesser General Public License for more details.
    + *
    + * You should have received a copy of the GNU Lesser General Public
    + * License along with this software; if not, write to the Free
    + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    + */
    +package org.xwiki.internal.document;
    +
    +import javax.inject.Named;
    +import javax.inject.Singleton;
    +
    +import org.xwiki.component.annotation.Component;
    +import org.xwiki.observation.AbstractEventListener;
    +import org.xwiki.observation.event.CancelableEvent;
    +import org.xwiki.observation.event.Event;
    +
    +import com.xpn.xwiki.doc.XWikiDocument;
    +import com.xpn.xwiki.internal.event.UserUpdatingDocumentEvent;
    +
    +/**
    + * Cancel any save that tries to save a new document if the document already exists.
    + *
    + * <p>
    + *     This can happen when the context document is set to an empty document because the user doesn't have view right,
    + *     but the user still has, e.g., edit right. In this situation, the user would still be able to to save but it is
    + *     hard to imagine a scenario where this would make sense. This listener therefore cancels the save in this
    + *     situation.
    + * </p>
    + *
    + * @version $Id$
    + * @since 14.10.21
    + * @since 15.5.5
    + * @since 15.10.6
    + */
    +@Component
    +@Singleton
    +@Named(DocumentOverrideListener.NAME)
    +public class DocumentOverrideListener extends AbstractEventListener
    +{
    +    /**
    +     * The unique identifier of the listener.
    +     */
    +    public static final String NAME = "org.xwiki.internal.document.DocumentOverrideListener";
    +
    +    /**
    +     * The default constructor.
    +     */
    +    public DocumentOverrideListener()
    +    {
    +        super(NAME, new UserUpdatingDocumentEvent());
    +    }
    +
    +    @Override
    +    public void onEvent(Event event, Object source, Object data)
    +    {
    +        XWikiDocument document = (XWikiDocument) source;
    +        XWikiDocument originalDocument = document.getOriginalDocument();
    +
    +        if (document.isNew() && originalDocument != null && !originalDocument.isNew()) {
    +            ((CancelableEvent) event).cancel(
    +                "The document already exists but the document to be saved is marked as new.");
    +        }
    +    }
    +}
    
  • xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt+1 0 modified
    @@ -278,3 +278,4 @@ org.xwiki.security.authservice.script.AuthServiceScriptService
     org.xwiki.model.validation.edit.XWikiDocumentLockEditConfirmationChecker
     org.xwiki.evaluation.internal.DefaultObjectEvaluator
     org.xwiki.evaluation.internal.VelocityObjectPropertyEvaluator
    +org.xwiki.internal.document.DocumentOverrideListener
    
  • xwiki-platform-core/xwiki-platform-oldcore/src/test/java/org/xwiki/internal/document/DocumentOverrideListenerTest.java+86 0 added
    @@ -0,0 +1,86 @@
    +/*
    + * See the NOTICE file distributed with this work for additional
    + * information regarding copyright ownership.
    + *
    + * This is free software; you can redistribute it and/or modify it
    + * under the terms of the GNU Lesser General Public License as
    + * published by the Free Software Foundation; either version 2.1 of
    + * the License, or (at your option) any later version.
    + *
    + * This software is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    + * Lesser General Public License for more details.
    + *
    + * You should have received a copy of the GNU Lesser General Public
    + * License along with this software; if not, write to the Free
    + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    + */
    +package org.xwiki.internal.document;
    +
    +import org.junit.jupiter.api.Test;
    +import org.xwiki.model.reference.DocumentReference;
    +import org.xwiki.observation.internal.DefaultObservationManager;
    +import org.xwiki.test.annotation.ComponentList;
    +
    +import com.xpn.xwiki.XWikiException;
    +import com.xpn.xwiki.doc.XWikiDocument;
    +import com.xpn.xwiki.test.MockitoOldcore;
    +import com.xpn.xwiki.test.junit5.mockito.InjectMockitoOldcore;
    +import com.xpn.xwiki.test.junit5.mockito.OldcoreTest;
    +import com.xpn.xwiki.test.reference.ReferenceComponentList;
    +
    +import static org.junit.jupiter.api.Assertions.assertEquals;
    +import static org.junit.jupiter.api.Assertions.assertFalse;
    +import static org.junit.jupiter.api.Assertions.assertThrows;
    +import static org.mockito.Mockito.mock;
    +
    +/**
    + * Unit tests for {@link DocumentOverrideListener}.
    + *
    + * @version $Id$
    + */
    +@OldcoreTest(mockXWiki = false)
    +@ReferenceComponentList
    +@ComponentList({ DefaultObservationManager.class, DocumentOverrideListener.class })
    +class DocumentOverrideListenerTest
    +{
    +    @InjectMockitoOldcore
    +    private MockitoOldcore oldcore;
    +
    +    @Test
    +    void savingNewDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext());
    +    }
    +
    +    @Test
    +    void savingExistingDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
    +        document = this.oldcore.getSpyXWiki().getDocument(documentReference, this.oldcore.getXWikiContext());
    +        assertFalse(document.isNew());
    +        this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext());
    +    }
    +
    +    @Test
    +    void savingOverridingExistingDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        DocumentReference userReference = new DocumentReference("wiki", "XWiki", "user");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
    +        XWikiDocument newDocument = new XWikiDocument(documentReference);
    +        XWikiException exception = assertThrows(XWikiException.class,
    +            () -> this.oldcore.getSpyXWiki()
    +                .checkSavingDocument(userReference, newDocument, this.oldcore.getXWikiContext()));
    +        assertEquals("Error number 9001 in 9: User [wiki:XWiki.user] has been denied the right to save the "
    +            + "document [wiki:space.page]. Reason: [The document already exists but the document to be saved is marked "
    +            + "as new.]", exception.getMessage());
    +    }
    +}
    
0bc27d6ec63c

XWIKI-21553: Do not override existing documents on user action (#2790)

https://github.com/xwiki/xwiki-platformMichael HamannJan 16, 2024via ghsa
3 files changed · +164 0
  • xwiki-platform-core/xwiki-platform-oldcore/src/main/java/org/xwiki/internal/document/DocumentOverrideListener.java+77 0 added
    @@ -0,0 +1,77 @@
    +/*
    + * See the NOTICE file distributed with this work for additional
    + * information regarding copyright ownership.
    + *
    + * This is free software; you can redistribute it and/or modify it
    + * under the terms of the GNU Lesser General Public License as
    + * published by the Free Software Foundation; either version 2.1 of
    + * the License, or (at your option) any later version.
    + *
    + * This software is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    + * Lesser General Public License for more details.
    + *
    + * You should have received a copy of the GNU Lesser General Public
    + * License along with this software; if not, write to the Free
    + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    + */
    +package org.xwiki.internal.document;
    +
    +import javax.inject.Named;
    +import javax.inject.Singleton;
    +
    +import org.xwiki.component.annotation.Component;
    +import org.xwiki.observation.AbstractEventListener;
    +import org.xwiki.observation.event.CancelableEvent;
    +import org.xwiki.observation.event.Event;
    +
    +import com.xpn.xwiki.doc.XWikiDocument;
    +import com.xpn.xwiki.internal.event.UserUpdatingDocumentEvent;
    +
    +/**
    + * Cancel any save that tries to save a new document if the document already exists.
    + *
    + * <p>
    + *     This can happen when the context document is set to an empty document because the user doesn't have view right,
    + *     but the user still has, e.g., edit right. In this situation, the user would still be able to to save but it is
    + *     hard to imagine a scenario where this would make sense. This listener therefore cancels the save in this
    + *     situation.
    + * </p>
    + *
    + * @version $Id$
    + * @since 14.10.21
    + * @since 15.5.5
    + * @since 15.10.6
    + */
    +@Component
    +@Singleton
    +@Named(DocumentOverrideListener.NAME)
    +public class DocumentOverrideListener extends AbstractEventListener
    +{
    +    /**
    +     * The unique identifier of the listener.
    +     */
    +    public static final String NAME = "org.xwiki.internal.document.DocumentOverrideListener";
    +
    +    /**
    +     * The default constructor.
    +     */
    +    public DocumentOverrideListener()
    +    {
    +        super(NAME, new UserUpdatingDocumentEvent());
    +    }
    +
    +    @Override
    +    public void onEvent(Event event, Object source, Object data)
    +    {
    +        XWikiDocument document = (XWikiDocument) source;
    +        XWikiDocument originalDocument = document.getOriginalDocument();
    +
    +        if (document.isNew() && originalDocument != null && !originalDocument.isNew()) {
    +            ((CancelableEvent) event).cancel(
    +                "The document already exists but the document to be saved is marked as new.");
    +        }
    +    }
    +}
    
  • xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt+1 0 modified
    @@ -272,3 +272,4 @@ org.xwiki.internal.migration.InvitationInternalDocumentParameterEscapingFixer
     org.xwiki.internal.migration.InvitationInternalDocumentParameterEscapingTaskConsumer
     org.xwiki.evaluation.internal.DefaultObjectEvaluator
     org.xwiki.evaluation.internal.VelocityObjectPropertyEvaluator
    +org.xwiki.internal.document.DocumentOverrideListener
    
  • xwiki-platform-core/xwiki-platform-oldcore/src/test/java/org/xwiki/internal/document/DocumentOverrideListenerTest.java+86 0 added
    @@ -0,0 +1,86 @@
    +/*
    + * See the NOTICE file distributed with this work for additional
    + * information regarding copyright ownership.
    + *
    + * This is free software; you can redistribute it and/or modify it
    + * under the terms of the GNU Lesser General Public License as
    + * published by the Free Software Foundation; either version 2.1 of
    + * the License, or (at your option) any later version.
    + *
    + * This software is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    + * Lesser General Public License for more details.
    + *
    + * You should have received a copy of the GNU Lesser General Public
    + * License along with this software; if not, write to the Free
    + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    + */
    +package org.xwiki.internal.document;
    +
    +import org.junit.jupiter.api.Test;
    +import org.xwiki.model.reference.DocumentReference;
    +import org.xwiki.observation.internal.DefaultObservationManager;
    +import org.xwiki.test.annotation.ComponentList;
    +
    +import com.xpn.xwiki.XWikiException;
    +import com.xpn.xwiki.doc.XWikiDocument;
    +import com.xpn.xwiki.test.MockitoOldcore;
    +import com.xpn.xwiki.test.junit5.mockito.InjectMockitoOldcore;
    +import com.xpn.xwiki.test.junit5.mockito.OldcoreTest;
    +import com.xpn.xwiki.test.reference.ReferenceComponentList;
    +
    +import static org.junit.jupiter.api.Assertions.assertEquals;
    +import static org.junit.jupiter.api.Assertions.assertFalse;
    +import static org.junit.jupiter.api.Assertions.assertThrows;
    +import static org.mockito.Mockito.mock;
    +
    +/**
    + * Unit tests for {@link DocumentOverrideListener}.
    + *
    + * @version $Id$
    + */
    +@OldcoreTest(mockXWiki = false)
    +@ReferenceComponentList
    +@ComponentList({ DefaultObservationManager.class, DocumentOverrideListener.class })
    +class DocumentOverrideListenerTest
    +{
    +    @InjectMockitoOldcore
    +    private MockitoOldcore oldcore;
    +
    +    @Test
    +    void savingNewDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext());
    +    }
    +
    +    @Test
    +    void savingExistingDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
    +        document = this.oldcore.getSpyXWiki().getDocument(documentReference, this.oldcore.getXWikiContext());
    +        assertFalse(document.isNew());
    +        this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext());
    +    }
    +
    +    @Test
    +    void savingOverridingExistingDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        DocumentReference userReference = new DocumentReference("wiki", "XWiki", "user");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
    +        XWikiDocument newDocument = new XWikiDocument(documentReference);
    +        XWikiException exception = assertThrows(XWikiException.class,
    +            () -> this.oldcore.getSpyXWiki()
    +                .checkSavingDocument(userReference, newDocument, this.oldcore.getXWikiContext()));
    +        assertEquals("Error number 9001 in 9: User [wiki:XWiki.user] has been denied the right to save the "
    +            + "document [wiki:space.page]. Reason: [The document already exists but the document to be saved is marked "
    +            + "as new.]", exception.getMessage());
    +    }
    +}
    
c5efc1e519e7

XWIKI-21553: Do not override existing documents on user action (#2790)

https://github.com/xwiki/xwiki-platformMichael HamannJan 16, 2024via ghsa
3 files changed · +164 0
  • xwiki-platform-core/xwiki-platform-oldcore/src/main/java/org/xwiki/internal/document/DocumentOverrideListener.java+77 0 added
    @@ -0,0 +1,77 @@
    +/*
    + * See the NOTICE file distributed with this work for additional
    + * information regarding copyright ownership.
    + *
    + * This is free software; you can redistribute it and/or modify it
    + * under the terms of the GNU Lesser General Public License as
    + * published by the Free Software Foundation; either version 2.1 of
    + * the License, or (at your option) any later version.
    + *
    + * This software is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    + * Lesser General Public License for more details.
    + *
    + * You should have received a copy of the GNU Lesser General Public
    + * License along with this software; if not, write to the Free
    + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    + */
    +package org.xwiki.internal.document;
    +
    +import javax.inject.Named;
    +import javax.inject.Singleton;
    +
    +import org.xwiki.component.annotation.Component;
    +import org.xwiki.observation.AbstractEventListener;
    +import org.xwiki.observation.event.CancelableEvent;
    +import org.xwiki.observation.event.Event;
    +
    +import com.xpn.xwiki.doc.XWikiDocument;
    +import com.xpn.xwiki.internal.event.UserUpdatingDocumentEvent;
    +
    +/**
    + * Cancel any save that tries to save a new document if the document already exists.
    + *
    + * <p>
    + *     This can happen when the context document is set to an empty document because the user doesn't have view right,
    + *     but the user still has, e.g., edit right. In this situation, the user would still be able to to save but it is
    + *     hard to imagine a scenario where this would make sense. This listener therefore cancels the save in this
    + *     situation.
    + * </p>
    + *
    + * @version $Id$
    + * @since 14.10.21
    + * @since 15.5.5
    + * @since 15.10.6
    + */
    +@Component
    +@Singleton
    +@Named(DocumentOverrideListener.NAME)
    +public class DocumentOverrideListener extends AbstractEventListener
    +{
    +    /**
    +     * The unique identifier of the listener.
    +     */
    +    public static final String NAME = "org.xwiki.internal.document.DocumentOverrideListener";
    +
    +    /**
    +     * The default constructor.
    +     */
    +    public DocumentOverrideListener()
    +    {
    +        super(NAME, new UserUpdatingDocumentEvent());
    +    }
    +
    +    @Override
    +    public void onEvent(Event event, Object source, Object data)
    +    {
    +        XWikiDocument document = (XWikiDocument) source;
    +        XWikiDocument originalDocument = document.getOriginalDocument();
    +
    +        if (document.isNew() && originalDocument != null && !originalDocument.isNew()) {
    +            ((CancelableEvent) event).cancel(
    +                "The document already exists but the document to be saved is marked as new.");
    +        }
    +    }
    +}
    
  • xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt+1 0 modified
    @@ -278,3 +278,4 @@ org.xwiki.security.authservice.script.AuthServiceScriptService
     org.xwiki.model.validation.edit.XWikiDocumentLockEditConfirmationChecker
     org.xwiki.evaluation.internal.DefaultObjectEvaluator
     org.xwiki.evaluation.internal.VelocityObjectPropertyEvaluator
    +org.xwiki.internal.document.DocumentOverrideListener
    
  • xwiki-platform-core/xwiki-platform-oldcore/src/test/java/org/xwiki/internal/document/DocumentOverrideListenerTest.java+86 0 added
    @@ -0,0 +1,86 @@
    +/*
    + * See the NOTICE file distributed with this work for additional
    + * information regarding copyright ownership.
    + *
    + * This is free software; you can redistribute it and/or modify it
    + * under the terms of the GNU Lesser General Public License as
    + * published by the Free Software Foundation; either version 2.1 of
    + * the License, or (at your option) any later version.
    + *
    + * This software is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    + * Lesser General Public License for more details.
    + *
    + * You should have received a copy of the GNU Lesser General Public
    + * License along with this software; if not, write to the Free
    + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    + */
    +package org.xwiki.internal.document;
    +
    +import org.junit.jupiter.api.Test;
    +import org.xwiki.model.reference.DocumentReference;
    +import org.xwiki.observation.internal.DefaultObservationManager;
    +import org.xwiki.test.annotation.ComponentList;
    +
    +import com.xpn.xwiki.XWikiException;
    +import com.xpn.xwiki.doc.XWikiDocument;
    +import com.xpn.xwiki.test.MockitoOldcore;
    +import com.xpn.xwiki.test.junit5.mockito.InjectMockitoOldcore;
    +import com.xpn.xwiki.test.junit5.mockito.OldcoreTest;
    +import com.xpn.xwiki.test.reference.ReferenceComponentList;
    +
    +import static org.junit.jupiter.api.Assertions.assertEquals;
    +import static org.junit.jupiter.api.Assertions.assertFalse;
    +import static org.junit.jupiter.api.Assertions.assertThrows;
    +import static org.mockito.Mockito.mock;
    +
    +/**
    + * Unit tests for {@link DocumentOverrideListener}.
    + *
    + * @version $Id$
    + */
    +@OldcoreTest(mockXWiki = false)
    +@ReferenceComponentList
    +@ComponentList({ DefaultObservationManager.class, DocumentOverrideListener.class })
    +class DocumentOverrideListenerTest
    +{
    +    @InjectMockitoOldcore
    +    private MockitoOldcore oldcore;
    +
    +    @Test
    +    void savingNewDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext());
    +    }
    +
    +    @Test
    +    void savingExistingDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
    +        document = this.oldcore.getSpyXWiki().getDocument(documentReference, this.oldcore.getXWikiContext());
    +        assertFalse(document.isNew());
    +        this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext());
    +    }
    +
    +    @Test
    +    void savingOverridingExistingDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        DocumentReference userReference = new DocumentReference("wiki", "XWiki", "user");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
    +        XWikiDocument newDocument = new XWikiDocument(documentReference);
    +        XWikiException exception = assertThrows(XWikiException.class,
    +            () -> this.oldcore.getSpyXWiki()
    +                .checkSavingDocument(userReference, newDocument, this.oldcore.getXWikiContext()));
    +        assertEquals("Error number 9001 in 9: User [wiki:XWiki.user] has been denied the right to save the "
    +            + "document [wiki:space.page]. Reason: [The document already exists but the document to be saved is marked "
    +            + "as new.]", exception.getMessage());
    +    }
    +}
    
56f5d8aab737

XWIKI-21553: Do not override existing documents on user action (#2790)

https://github.com/xwiki/xwiki-platformMichael HamannJan 16, 2024via ghsa
3 files changed · +164 0
  • xwiki-platform-core/xwiki-platform-oldcore/src/main/java/org/xwiki/internal/document/DocumentOverrideListener.java+77 0 added
    @@ -0,0 +1,77 @@
    +/*
    + * See the NOTICE file distributed with this work for additional
    + * information regarding copyright ownership.
    + *
    + * This is free software; you can redistribute it and/or modify it
    + * under the terms of the GNU Lesser General Public License as
    + * published by the Free Software Foundation; either version 2.1 of
    + * the License, or (at your option) any later version.
    + *
    + * This software is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    + * Lesser General Public License for more details.
    + *
    + * You should have received a copy of the GNU Lesser General Public
    + * License along with this software; if not, write to the Free
    + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    + */
    +package org.xwiki.internal.document;
    +
    +import javax.inject.Named;
    +import javax.inject.Singleton;
    +
    +import org.xwiki.component.annotation.Component;
    +import org.xwiki.observation.AbstractEventListener;
    +import org.xwiki.observation.event.CancelableEvent;
    +import org.xwiki.observation.event.Event;
    +
    +import com.xpn.xwiki.doc.XWikiDocument;
    +import com.xpn.xwiki.internal.event.UserUpdatingDocumentEvent;
    +
    +/**
    + * Cancel any save that tries to save a new document if the document already exists.
    + *
    + * <p>
    + *     This can happen when the context document is set to an empty document because the user doesn't have view right,
    + *     but the user still has, e.g., edit right. In this situation, the user would still be able to to save but it is
    + *     hard to imagine a scenario where this would make sense. This listener therefore cancels the save in this
    + *     situation.
    + * </p>
    + *
    + * @version $Id$
    + * @since 14.10.21
    + * @since 15.5.5
    + * @since 15.10.6
    + */
    +@Component
    +@Singleton
    +@Named(DocumentOverrideListener.NAME)
    +public class DocumentOverrideListener extends AbstractEventListener
    +{
    +    /**
    +     * The unique identifier of the listener.
    +     */
    +    public static final String NAME = "org.xwiki.internal.document.DocumentOverrideListener";
    +
    +    /**
    +     * The default constructor.
    +     */
    +    public DocumentOverrideListener()
    +    {
    +        super(NAME, new UserUpdatingDocumentEvent());
    +    }
    +
    +    @Override
    +    public void onEvent(Event event, Object source, Object data)
    +    {
    +        XWikiDocument document = (XWikiDocument) source;
    +        XWikiDocument originalDocument = document.getOriginalDocument();
    +
    +        if (document.isNew() && originalDocument != null && !originalDocument.isNew()) {
    +            ((CancelableEvent) event).cancel(
    +                "The document already exists but the document to be saved is marked as new.");
    +        }
    +    }
    +}
    
  • xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt+1 0 modified
    @@ -278,3 +278,4 @@ org.xwiki.security.authservice.internal.StandardXWikiAuthServiceComponent
     org.xwiki.security.authservice.script.AuthServiceScriptService
     org.xwiki.evaluation.internal.DefaultObjectEvaluator
     org.xwiki.evaluation.internal.VelocityObjectPropertyEvaluator
    +org.xwiki.internal.document.DocumentOverrideListener
    
  • xwiki-platform-core/xwiki-platform-oldcore/src/test/java/org/xwiki/internal/document/DocumentOverrideListenerTest.java+86 0 added
    @@ -0,0 +1,86 @@
    +/*
    + * See the NOTICE file distributed with this work for additional
    + * information regarding copyright ownership.
    + *
    + * This is free software; you can redistribute it and/or modify it
    + * under the terms of the GNU Lesser General Public License as
    + * published by the Free Software Foundation; either version 2.1 of
    + * the License, or (at your option) any later version.
    + *
    + * This software is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    + * Lesser General Public License for more details.
    + *
    + * You should have received a copy of the GNU Lesser General Public
    + * License along with this software; if not, write to the Free
    + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    + */
    +package org.xwiki.internal.document;
    +
    +import org.junit.jupiter.api.Test;
    +import org.xwiki.model.reference.DocumentReference;
    +import org.xwiki.observation.internal.DefaultObservationManager;
    +import org.xwiki.test.annotation.ComponentList;
    +
    +import com.xpn.xwiki.XWikiException;
    +import com.xpn.xwiki.doc.XWikiDocument;
    +import com.xpn.xwiki.test.MockitoOldcore;
    +import com.xpn.xwiki.test.junit5.mockito.InjectMockitoOldcore;
    +import com.xpn.xwiki.test.junit5.mockito.OldcoreTest;
    +import com.xpn.xwiki.test.reference.ReferenceComponentList;
    +
    +import static org.junit.jupiter.api.Assertions.assertEquals;
    +import static org.junit.jupiter.api.Assertions.assertFalse;
    +import static org.junit.jupiter.api.Assertions.assertThrows;
    +import static org.mockito.Mockito.mock;
    +
    +/**
    + * Unit tests for {@link DocumentOverrideListener}.
    + *
    + * @version $Id$
    + */
    +@OldcoreTest(mockXWiki = false)
    +@ReferenceComponentList
    +@ComponentList({ DefaultObservationManager.class, DocumentOverrideListener.class })
    +class DocumentOverrideListenerTest
    +{
    +    @InjectMockitoOldcore
    +    private MockitoOldcore oldcore;
    +
    +    @Test
    +    void savingNewDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext());
    +    }
    +
    +    @Test
    +    void savingExistingDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
    +        document = this.oldcore.getSpyXWiki().getDocument(documentReference, this.oldcore.getXWikiContext());
    +        assertFalse(document.isNew());
    +        this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext());
    +    }
    +
    +    @Test
    +    void savingOverridingExistingDocument() throws Exception
    +    {
    +        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    +        DocumentReference userReference = new DocumentReference("wiki", "XWiki", "user");
    +        XWikiDocument document = new XWikiDocument(documentReference);
    +        this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
    +        XWikiDocument newDocument = new XWikiDocument(documentReference);
    +        XWikiException exception = assertThrows(XWikiException.class,
    +            () -> this.oldcore.getSpyXWiki()
    +                .checkSavingDocument(userReference, newDocument, this.oldcore.getXWikiContext()));
    +        assertEquals("Error number 9001 in 9: User [wiki:XWiki.user] has been denied the right to save the "
    +            + "document [wiki:space.page]. Reason: [The document already exists but the document to be saved is marked "
    +            + "as new.]", exception.getMessage());
    +    }
    +}
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

8

News mentions

0

No linked articles in our index yet.