This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-c11e7a91-5a98-4a78-beb8-0ff0fb548c4d XWIKI-25432 Open

A wiki macro stays registered with its old definition when its document is deleted or no longer grants the right its visibility needs

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-dfc3f2cf-6e52-4f41-acb0-ffe45c14b5e3 Michael Hamann created this issue on 21/Oct/26 10:44
 
Summary: A wiki macro stays registered with its old definition when its document is deleted or no longer grants the right its visibility needs
Issue Type: cid:jira-generated-image-avatar-c11e7a91-5a98-4a78-beb8-0ff0fb548c4d Bug
Affects Versions: 17.10.14, 18.4.7, 18.8.0
Assignee: Unassigned
Components: Rendering - WikiMacro
Created: 21/Oct/26 10:44
Priority: cid:jira-generated-image-static-major-4dde2509-fc18-4808-8fe6-26e4e1d78880 Major
Reporter: Michael Hamann
Description:

Steps to reproduce

  • Create a page with an XWiki.WikiMacroClass object, visibility Current Wiki (the default), id mymacro and code v1, and a page containing {{mymacro/}}.
  • Delete the macro page.
  • Look at the page using the macro (or any new page using it).

A second variant: enforce Script right on the macro page ("Information" > "Review required rights"), then change the macro code to v2.

Expected result

The macro is unregistered when its page is deleted (Unknown macro: mymacro). In the variant, the macro is unregistered as soon as its document no longer grants the right its visibility requires, as is the case after a restart.

Actual result

The deleted macro keeps rendering v1 until the next restart. In the variant, the macro keeps rendering v1: the update is silently ignored, and the macro only disappears at the next restart (or XAR import), far away from the change that caused it. With DEBUG logging for org.xwiki.rendering.internal.macro.wikibridge enabled:

DEBUG r.i.m.w.WikiMacroEventListener - Unable to unregister macro in document [xwiki:Space.Macro]
org.xwiki.rendering.macro.wikibridge.WikiMacroException: Unable to unregister macro [mymacro] in [xwiki:Space.Macro] for visibility [WIKI] due to insufficient privileges
	at org.xwiki.rendering.internal.macro.wikibridge.DefaultWikiMacroManager.unregisterWikiMacro(DefaultWikiMacroManager.java:239)
	at org.xwiki.rendering.internal.macro.wikibridge.WikiMacroEventListener.unregisterMacro(WikiMacroEventListener.java:171)

Why

DefaultWikiMacroManager.unregisterWikiMacro calls WikiMacroFactory.isAllowed for the macro's visibility and refuses to unregister when it returns false. isAllowed checks the right against the current state of the document: its current author, and since required rights, the rights it enforces. So unregistration fails exactly when the document stopped granting the right:

  • a deleted document has no author, so the check always fails for Current Wiki and Global macros;
  • an author without the right, or enforced required rights below it (e.g. Script for a Current Wiki macro), make it fail too.

WikiMacroEventListener then also skips the re-registration, so the old macro, with its old code and author, stays registered until the next restart, when registration fails and the macro disappears.

Unregistering never grants anything and unregisterWikiMacro is only called by the listener and the initializer, in reaction to a change of the document that was already authorized. Only registration needs the rights check.

How it was found

While taking screenshots for XWIKI-24822 on 18.10.0-SNAPSHOT: enforcing Script on a wiki-visible macro page didn't break the macro as XWIKI-24822 describes; the stale registration explained why. Reproduced on 18.10.0-SNAPSHOT; the same check is on stable-17.10.x and stable-18.4.x, and dates back to XWIKI-7880.