Site JS reauth hack can be bypassed using 'centralauthtoken'. I realized this while writing this reply on the other task: T419621, T419621#11827741. 'centralauthtoken' auth can, in fact, be used from a browser that could be running malicious code, so this should not be allowed.
This assumes that you have WikimediaCustomizations and CentralAuth installed on your wiki.
API edits while not recently authenticated are supposed to be rejected. This behaves correctly (fails with userlogin-reauth error):
await (new mw.Api).edit('MediaWiki:Common.js', (revision) => revision.content + '// test');
This, however, succeeds in saving the edit, but it should fail with the same error:
mw.ForeignApi.prototype.checkForeignLogin = () => $.Deferred().reject(); // Make sure that the 'centralauthtoken' code path in CentralAuth is used await (new mw.ForeignApi(mw.util.wikiScript('api'))).edit('MediaWiki:Common.js', (revision) => revision.content + '// test');
The fix for this would be to resolve T419353, and then make it so that CentralAuthTokenSessionProvider does not allow sensitive operations.