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(plus): load stripe.js for fraud prevention #9318

Merged
merged 2 commits into from
Oct 30, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { useOnlineStatus } from "../../../hooks";
import { useGleanClick } from "../../../telemetry/glean-context";
import { OFFER_OVERVIEW_CLICK } from "../../../telemetry/constants";
import LogInLink from "../../../ui/atoms/login-link";
import React from "react";

const Stripe = React.lazy(() => import("./stripe"));

export enum Period {
Month,
Expand Down Expand Up @@ -167,6 +170,7 @@ function OfferDetails({
}).format(monthlyPrice / 100);
return (
<section className="subscribe-detail" id={offerDetails.id}>
<Stripe></Stripe>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Stripe></Stripe>
<Stripe />

<h3>{offerDetails.name}</h3>
<div className="sub-info">
{(displayMonthlyPrice && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import "@stripe/stripe-js";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's better to use an async import() rather than React.lazy. I'm unsure how something like:

export default function Stripe() {
  (async () => {
    await import("@stripe/stripe-js");
  })()
  return null
}

behaves with re-renders. I guess you could wrap it in a useCallback, but then is it any less "reacty" than just using React.lazy?

export default function Stripe() {
return <></>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think generally better:

Suggested change
return <></>;
return null;

}
4 changes: 4 additions & 0 deletions libs/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export const CSP_SCRIPT_SRC_VALUES = [
"assets.codepen.io",
"production-assets.codepen.io",

"https://js.stripe.com",

/*
* Inline scripts (defined in `client/public/index.html`).
*
Expand Down Expand Up @@ -104,6 +106,7 @@ export const CSP_DIRECTIVES = {

"www.google-analytics.com",
"stats.g.doubleclick.net",
"https://api.stripe.com",
],
"font-src": ["'self'"],
"frame-src": [
Expand All @@ -122,6 +125,7 @@ export const CSP_DIRECTIVES = {
"www.youtube-nocookie.com",
"codepen.io",
"survey.alchemer.com",
"https://js.stripe.com",
],
"img-src": [
"'self'",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"@mozilla/glean": "2.0.5",
"@sentry/integrations": "^7.75.1",
"@sentry/node": "^7.75.1",
"@stripe/stripe-js": "^2.1.10",
"@use-it/interval": "^1.0.0",
"@vscode/ripgrep": "^1.15.6",
"@webref/css": "^6.0.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,11 @@
dependencies:
"@sinonjs/commons" "^2.0.0"

"@stripe/stripe-js@^2.1.10":
version "2.1.10"
resolved "https://registry.yarnpkg.com/@stripe/stripe-js/-/stripe-js-2.1.10.tgz#d5f0a85def710e7a798e18e9950c4ef619dab917"
integrity sha512-h79zhwvxAJVAvtVjtMoz++DtwI7GdcEItmTC0P2gciZoFUeAO6XX9DL+UXm9uADiEaUvTKqrExYwtBTlMYAaPA==

"@supabase/functions-js@^2.1.5":
version "2.1.5"
resolved "https://registry.yarnpkg.com/@supabase/functions-js/-/functions-js-2.1.5.tgz#ed1b85f499dfda21d40fe39b86ab923117cb572b"
Expand Down