Skip to content

Commit

Permalink
Remove stripe dependencies (#44328)
Browse files Browse the repository at this point in the history
  • Loading branch information
michellescripts authored Aug 5, 2024
1 parent 2bad97e commit 87a0a1c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 69 deletions.
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

0 comments on commit 87a0a1c

Please sign in to comment.