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

Remove stripe dependencies #44328

Merged
merged 1 commit into from
Aug 5, 2024
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
20 changes: 4 additions & 16 deletions lib/httplib/httpheaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ var defaultContentSecurityPolicy = CSPMap{
var defaultFontSrc = CSPMap{"font-src": {"'self'", "data:"}}
var defaultConnectSrc = CSPMap{"connect-src": {"'self'", "wss:"}}

var stripeSecurityPolicy = CSPMap{
// auto-pay plans in Cloud use stripe.com to manage billing information
"script-src": {"https://js.stripe.com"},
"frame-src": {"https://js.stripe.com"},
}

var wasmSecurityPolicy = CSPMap{
"script-src": {"'self'", "'wasm-unsafe-eval'"},
}
Expand Down Expand Up @@ -176,13 +170,9 @@ func SetDefaultSecurityHeaders(h http.Header) {
h.Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains")
}

func getIndexContentSecurityPolicy(withStripe, withWasm bool) CSPMap {
func getIndexContentSecurityPolicy(withWasm bool) CSPMap {
cspMaps := []CSPMap{defaultContentSecurityPolicy, defaultFontSrc, defaultConnectSrc}

if withStripe {
cspMaps = append(cspMaps, stripeSecurityPolicy)
}

if withWasm {
cspMaps = append(cspMaps, wasmSecurityPolicy)
}
Expand All @@ -202,19 +192,17 @@ var indexCSPStringCache *cspCache = newCSPCache()

func getIndexContentSecurityPolicyString(cfg proto.Features, urlPath string) string {
// Check for result with this cfg and urlPath in cache
withStripe := cfg.GetIsStripeManaged()
key := fmt.Sprintf("%v-%v", withStripe, urlPath)
if cspString, ok := indexCSPStringCache.get(key); ok {
if cspString, ok := indexCSPStringCache.get(urlPath); ok {
return cspString
}

// Nothing found in cache, calculate regex and result
withWasm := desktopSessionRe.MatchString(urlPath) || recordingRe.MatchString(urlPath)
cspString := GetContentSecurityPolicyString(
getIndexContentSecurityPolicy(withStripe, withWasm),
getIndexContentSecurityPolicy(withWasm),
)
// Add result to cache
indexCSPStringCache.set(key, cspString)
indexCSPStringCache.set(urlPath, cspString)

return cspString
}
Expand Down
29 changes: 5 additions & 24 deletions lib/httplib/httplib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func TestSetIndexContentSecurityPolicy(t *testing.T) {
expectedCspVals map[string]string
}{
{
name: "default (no stripe or wasm)",
name: "default (no wasm)",
features: proto.Features{},
urlPath: "/web/index.js",
expectedCspVals: map[string]string{
Expand All @@ -295,25 +295,7 @@ func TestSetIndexContentSecurityPolicy(t *testing.T) {
},
},
{
name: "for cloud based usage, Stripe managed product (with stripe, no wasm)",
features: proto.Features{Cloud: true, IsUsageBased: true, IsStripeManaged: true},
urlPath: "/web/index.js",
expectedCspVals: map[string]string{
"default-src": "'self'",
"base-uri": "'self'",
"form-action": "'self'",
"frame-ancestors": "'none'",
"frame-src": "https://js.stripe.com",
"object-src": "'none'",
"script-src": "'self' https://js.stripe.com",
"style-src": "'self' 'unsafe-inline'",
"img-src": "'self' data: blob:",
"font-src": "'self' data:",
"connect-src": "'self' wss:",
},
},
{
name: "for cloud based usage, EUB product (no stripe or wasm)",
name: "for cloud based usage, EUB product (no wasm)",
features: proto.Features{Cloud: true, IsUsageBased: true, ProductType: proto.ProductType_PRODUCT_TYPE_EUB},
urlPath: "/web/index.js",
expectedCspVals: map[string]string{
Expand All @@ -329,7 +311,7 @@ func TestSetIndexContentSecurityPolicy(t *testing.T) {
},
},
{
name: "for desktop session (no stripe, with wasm)",
name: "for desktop session (with wasm)",
features: proto.Features{},
urlPath: "/web/cluster/:clusterId/desktops/:desktopName/:username",
expectedCspVals: map[string]string{
Expand All @@ -346,7 +328,7 @@ func TestSetIndexContentSecurityPolicy(t *testing.T) {
},
},
{
name: "for cloud based usage & desktop session, Stripe managed product (with stripe, with wasm)",
name: "for cloud based usage & desktop session, with wasm",
features: proto.Features{Cloud: true, IsUsageBased: true, IsStripeManaged: true},
urlPath: "/web/cluster/:clusterId/desktops/:desktopName/:username",
expectedCspVals: map[string]string{
Expand All @@ -355,8 +337,7 @@ func TestSetIndexContentSecurityPolicy(t *testing.T) {
"form-action": "'self'",
"frame-ancestors": "'none'",
"object-src": "'none'",
"script-src": "'self' https://js.stripe.com 'wasm-unsafe-eval'",
"frame-src": "https://js.stripe.com",
"script-src": "'self' 'wasm-unsafe-eval'",
"style-src": "'self' 'unsafe-inline'",
"img-src": "'self' data: blob:",
"font-src": "'self' data:",
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
"@nivo/bar": "^0.87.0",
"@protobuf-ts/runtime": "^2.9.4",
"@protobuf-ts/runtime-rpc": "^2.9.4",
"@stripe/react-stripe-js": "^1.16.5",
"@stripe/stripe-js": "^1.48.0",
"@uiw/codemirror-themes": "^4.23.0",
"@uiw/react-codemirror": "^4.23.0",
"d3-scale": "^4.0.2",
Expand Down
25 changes: 0 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions web/packages/teleport/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ export enum NavTitle {

// Billing
BillingSummary = 'Summary',
PaymentsAndInvoices = 'Payments and Invoices',
InvoiceSettings = 'Invoice Settings',

// Clusters
ManageClusters = 'Manage Clusters',
Expand Down
Loading