Page MenuHomePhabricator

Make hCaptcha proxy URL compatible with MediaWiki CSP
Closed, ResolvedPublic

Description

This is to avoid reporting of many errors on the CSP audit logs, but it should still work anyway

Event Timeline

Reedy renamed this task from Make hCaptcha proxy URL compatible with Mediawiki CSP to Make hCaptcha proxy URL compatible with MediaWiki CSP.EditedMar 24 2025, 12:12 PM

Probably a config flag as to whether to set CSP headers.

And/or a $wg of values to be set, to allow them to be customised...

Change #1136349 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@master] hCaptcha: Add config to disable loading of hCaptcha CSP rules

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

^ Patch stops the adding of hcaptcha.com and *.hcaptcha.com to requests.

TBC if we need to add custom CSP rules for our proxy (maybe? maybe not). We may need/want to move the hard coded [ 'https://hcaptcha.com', 'https://*.hcaptcha.com' ] into a $wg to allow customisation too...

	/** @inheritDoc */
	public static function getCSPUrls() {
		return [ 'https://hcaptcha.com', 'https://*.hcaptcha.com' ];
	}

	/**
	 * Adds the CSP policies that are necessary for the captcha module to work in a CSP enforced
	 * setup.
	 *
	 * @param ContentSecurityPolicy $csp The CSP instance to add the policies to, this is usually to be
	 * obtained from {@link OutputPage::getCSP()}
	 */
	public static function addCSPSources( ContentSecurityPolicy $csp ) {
		foreach ( static::getCSPUrls() as $src ) {
			// Since frame-src is not supported
			$csp->addDefaultSrc( $src );
			$csp->addScriptSrc( $src );
			$csp->addStyleSrc( $src );
		}
	}

^ The above is explicitly called in HTMLHCaptchaField (VE?), but I'm not 100% sure if they get called through the normal flow for other actions...

Change #1143604 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@master] hCaptcha: Variable-ise CSP URLs

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

Change #1143604 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@master] hCaptcha: Variable-ise CSP URLs

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

Change #1136349 abandoned by Reedy:

[mediawiki/extensions/ConfirmEdit@master] hCaptcha: Add config to disable loading of hCaptcha CSP rules

Reason:

In favour of https://gerrit.wikimedia.org/r/c/mediawiki/extensions/ConfirmEdit/+/1143604

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

Change #1161486 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@master] HCaptcha: Fix getCSPUrls()

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

Change #1161486 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@master] HCaptcha: Fix getCSPUrls()

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

Change #1163034 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@REL1_44] hCaptcha: Variable-ise CSP URLs

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

Change #1163035 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@REL1_44] HCaptcha: Fix getCSPUrls()

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

Change #1163034 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@REL1_44] hCaptcha: Variable-ise CSP URLs

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

Change #1163035 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@REL1_44] HCaptcha: Fix getCSPUrls()

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