Page MenuHomePhabricator

Sanitization of magic links in attributes should be disabled if magic links are disabled
Open, Needs TriagePublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  1. Open a wiki that has disabled magic links via $wgEnableMagicLinks (e.g. enwiki)
  2. Go to Special:ExpandTemplates
  3. Paste the sample wikitext (see below) and click "OK" to render it.
  4. Open a wiki that has enabled magic links via $wgEnableMagicLinks (e.g. mediawiki.org)
  5. Go to its Special:ExpandTemplates
  6. Paste the same sample wikitext and click "OK" to render it:
* RFC: {{anchorencode:RFC}}
* PMID: {{anchorencode:PMID}}
* ISBN: {{anchorencode:ISBN}}

* RFCAAA: {{anchorencode:RFCAAA}}
* PMIDAAA: {{anchorencode:PMIDAAA}}
* ISBNAAA: {{anchorencode:ISBNAAA}}

* RFC AAA: {{anchorencode:RFC AAA}}
* PMID AAA: {{anchorencode:PMID AAA}}
* ISBN AAA: {{anchorencode:ISBN AAA}}

What happens?:
The result (not the preview) for both contains the HTML character entities, introduced by function safeEncodeAttribute in Sanitizer.php:

* RFC: RFC
* PMID: PMID
* ISBN: ISBN

* RFCAAA: RFCAAA
* PMIDAAA: PMIDAAA
* ISBNAAA: ISBNAAA

* RFC AAA: RFC_AAA
* PMID AAA: PMID_AAA
* ISBN AAA: ISBN_AAA

What should have happened instead?:

  • Function safeEncodeAttribute should skip the sanitization, when the corresponding magic links are disabled. That is, it should follow the configuration parameter $wgEnableMagicLinks, like function magicLinkCallback does in Parser.php for RFC, PMID, and ISBN.
  • When the sanitization is enabled, function safeEncodeAttribute should check slightly harder for the required syntax of magic links. It should only do the sanitization when the attribute value has a trailing space (e.g. 'ISBN ' => 'ISBN_', instead of 'ISBN' => 'ISBN',)
  • The result of Special:ExpandTemplates for step 3 (disabled magic links) should be:
* RFC: RFC
* PMID: PMID
* ISBN: ISBN

* RFCAAA: RFCAAA
* PMIDAAA: PMIDAAA
* ISBNAAA: ISBNAAA

* RFC AAA: RFC_AAA
* PMID AAA: PMID_AAA
* ISBN AAA: ISBN_AAA
  • The result of Special:ExpandTemplates for step 6 (enabled magic links) should be:
* RFC: RFC
* PMID: PMID
* ISBN: ISBN

* RFCAAA: RFCAAA
* PMIDAAA: PMIDAAA
* ISBNAAA: ISBNAAA

* RFC AAA: RFC_AAA
* PMID AAA: PMID_AAA
* ISBN AAA: ISBN_AAA

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Related Objects

Event Timeline

Andrybak renamed this task from Sanitization done by to Sanitization of magic links in attributes should be disabled if magic links are disabled.Aug 1 2026, 10:21 PM
Andrybak updated the task description. (Show Details)

I suggest that instead of fixing this, support for these magic links be removed completely. This seems like basically an obsolete feature. Continuing to provide support for this adds complexity to the code base and, as this ticket demonstrates, increases the potential for future problems.

See T145604

Thanks very much for Andrybak's detailed report.

The Village pump discussion is already linked above, but I just wanted to mention it again, as various users there have proposed solutions, and any dev looking into this may want to have a look there to avoid possible duplication of investigative effort.