Page MenuHomePhabricator

UserGroupMembership::getLink() causes a significant portion of false positives for phan-taint-check-plugin
Closed, ResolvedPublic

Description

phan-taint-check-plugin does not take into account the actual values of variables or really do any flow analysis at all for that matter.

As a result, it cannot tell if the third argument to UserGroupMembership::getLink() is 'html' or 'wiki', even if its specified as a literal string in the method call. This results in a significant portion of the false positives from the tool.

So we could maybe try and special case phan-taint-check-plugin for this particular function (This would involve quite a bit of work to do properly. To do hackly would be less work). Or maybe we could split this function into UserGroupMembership::getLinkForWikitext() and UserGroupMembership::getLinkForHtml().

On one hand, tools should serve us not the other way around, we should not be forced to use coding constructs due to limitations of tools. On the other hand, the method is relatively new, and its a rather rare idiom in MediaWiki to control whether or not escaping happens via an argument (instead of different function name). I tend towards the splitting the function option, but I might be biased, and would like to hear futher opinions.

Event Timeline

If only PHP supported proper enums...

The function was previously split when it belonged to the User class (User::makeGroupLinkHTML and User::makeGroupLinkWiki) but I merged the two functions into one to eliminate duplication of logic. I don't really have an opinion on what should be done here.

Nice work on the taint tool btw, this is something we have needed for years.

Legoktm subscribed.

+1 to splitting the methods again. We can use a private helper function to avoid duplicating logic.

I definitely agree that we should use private methods to avoid code duplication as much as possible if we split the method.

Change 456879 had a related patch set uploaded (by Brian Wolff; owner: Brian Wolff):
[mediawiki/core@master] Split UserGroupMembership::getLink into 2 functions

https://gerrit.wikimedia.org/r/456879

Change 456879 abandoned by Brian Wolff:
Refactor UserGroupMembership

Reason:
I don't really care about this anymore. Please feel free to take this over if anyone is interested.

https://gerrit.wikimedia.org/r/456879

This is still causing many false positives. I agree with everything that was written above, including that taint-check cannot properly handle this case, that adding a hack would be trivial but it shouldn't become the standard way to fix issues in code, and that splitting this method seems a very good idea, regardless of taint-check. So I'm submitting a slim patch that does just the splitting now.

Change 655688 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/core@master] Split UserGroupMembership::getLink

https://gerrit.wikimedia.org/r/655688

Change 655688 merged by jenkins-bot:

[mediawiki/core@master] user: Split and deprecate UserGroupMembership::getLink method

https://gerrit.wikimedia.org/r/655688

The remaining thing to do is replacing all occurrences of the old method and fixing phan issues as needed. I'll try to do that.

Change 921618 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/core@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921618

Change 921618 merged by jenkins-bot:

[mediawiki/core@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921618

Change 921680 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/extensions/CentralAuth@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921680

Change 921681 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/extensions/CheckUser@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921681

Change 921684 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/extensions/MobileFrontend@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921684

Change 921681 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921681

Change 921680 merged by jenkins-bot:

[mediawiki/extensions/CentralAuth@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921680

Change 921684 merged by jenkins-bot:

[mediawiki/extensions/MobileFrontend@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921684

Change 921554 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/extensions/Lockdown@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921554

Change 921555 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/extensions/OATHAuth@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921555

I've sent patches for all repos with phan enabled. Once those are meged, this task can be closed and UserGroupMembership::getLink() will follow the usual deprecation cycle.

Change 921555 merged by jenkins-bot:

[mediawiki/extensions/OATHAuth@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921555

Change 921554 merged by jenkins-bot:

[mediawiki/extensions/Lockdown@master] Replace usages of deprecated UserGroupMembership::getLink()

https://gerrit.wikimedia.org/r/921554