Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Cloudflare tokens issuance domain #397

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Home page: **[https://privacypass.github.io][pp-home]**
**Privacy Pass Providers:** 🟩 [Cloudflare][cf-url] 🟩 [hCaptcha][hc-url]

[pp-home]: https://privacypass.github.io/
[cf-url]: https://captcha.website/
[cf-url]: https://issuance.privacypass.cloudflare.com/
[hc-url]: https://www.hcaptcha.com/privacy-pass/
[chrome-store]: https://chrome.google.com/webstore/detail/privacy-pass/ajhmfdgkijocedmfjonnpjfojldioehi/
[firefox-store]: https://addons.mozilla.org/firefox/addon/privacy-pass/
Expand Down
6 changes: 4 additions & 2 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
// TODO It's better to move this to the provider class. Let's figure out how to do it later.
// Removes cookies for captcha.website to enable getting more tokens in the future.
chrome.cookies.onChanged.addListener((changeInfo) => {
const cloudflareDomains = ['captcha.website', 'issuance.privacypass.cloudflare.com'];
const domain = changeInfo.cookie.domain.replace(/^\./, '');
if (
!changeInfo.removed &&
changeInfo.cookie.domain === '.captcha.website' &&
cloudflareDomains.includes(domain) &&
changeInfo.cookie.name === 'cf_clearance'
) {
chrome.cookies.remove({ url: 'https://captcha.website', name: 'cf_clearance' });
chrome.cookies.remove({ url: `https://${domain}`, name: 'cf_clearance' });
}
});
14 changes: 14 additions & 0 deletions src/background/providers/cloudflare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,20 @@ describe('redemption', () => {
expect(result).toBeUndefined();
});

test('issuance.privacypass.cloudflare.com response', () => {
const storage = new StorageMock();
const updateIcon = jest.fn();
const navigateUrl = jest.fn();

const provider = new CloudflareProvider(storage, { updateIcon, navigateUrl });
const tokens = [new Token(), new Token(), new Token()];
provider['setStoredTokens'](tokens);
const details = validDetails;
details.url = 'https://issuance.privacypass.cloudflare.com/';
const result = provider.handleHeadersReceived(details);
expect(result).toBeUndefined();
});

/*
* The response is invalid if any of the followings is true:
* 1. The status code is not 403.
Expand Down
4 changes: 2 additions & 2 deletions src/background/providers/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const COMMITMENT_URL =
const QUALIFIED_BODY_PARAMS = ['md'];

const CHL_BYPASS_SUPPORT = 'cf-chl-bypass';
const DEFAULT_ISSUING_HOSTNAME = 'captcha.website';
const ISSUING_HOSTNAMES = ['captcha.website', 'issuance.privacypass.cloudflare.com'];

const REFERER_QUERY_PARAM = '__cf_chl_tk';
const QUERY_PARAM = '__cf_chl_f_tk';
Expand Down Expand Up @@ -317,7 +317,7 @@ export class CloudflareProvider implements Provider {
): chrome.webRequest.BlockingResponse | void {
// Don't redeem a token in the issuing website.
const url = new URL(details.url);
if (url.host === DEFAULT_ISSUING_HOSTNAME) {
if (ISSUING_HOSTNAMES.includes(url.host)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/popup/components/CloudflareButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function CloudflareButton(): JSX.Element {
});

const openHomePage = () => {
chrome.tabs.create({ url: 'https://captcha.website' });
chrome.tabs.create({ url: 'https://issuance.privacypass.cloudflare.com' });
};

return (
Expand Down