Skip to content

Commit a978d2c

Browse files
Add tenant.AllowedSchemes advanced configuration item (#1332)
* Add tenant.AllowedSchemes advanced configuration item Specifying ^monero:[48] or ^bitcoin:(1|3|bc1) allows cryptocurrency payment links These were rendered but then sanitised away to <a>...</a> w/o href= Ref: https://bounties.monero.social/posts/15/1-200m-monero-bounties-site-parse-donation-address-as-link * Ship the config via useFider() * Work around useContext() restrixion in test * Disable allowed schemes by setting ALLOW_ALLOWED_SCHEMES=false * Hide Allowed URL Schemes config if disabled * Bump migration date
1 parent 73539bc commit a978d2c

25 files changed

Lines changed: 108 additions & 33 deletions

File tree

.example.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ BASE_URL=http://localhost:3000
22
GO_ENV=development
33
DATABASE_URL=postgres://fider:fider_pw@localhost:5555/fider?sslmode=disable
44
JWT_SECRET=hsjl]W;&ZcHxT&FK;s%bgIQF:#ch=~#Al4:5]N;7V<qPZ3e9lT4'%;go;LIkc%k
5+
# ALLOW_ALLOWED_SCHEMES=false
56

67
LOG_LEVEL=DEBUG
78
LOG_CONSOLE=true

app/actions/tenant.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ func (action *UpdateTenantSettings) Validate(ctx context.Context, user *entity.U
177177

178178
// UpdateTenantAdvancedSettings is the input model used to update tenant advanced settings
179179
type UpdateTenantAdvancedSettings struct {
180-
CustomCSS string `json:"customCSS"`
180+
CustomCSS string `json:"customCSS"`
181+
AllowedSchemes string `json:"allowedSchemes"`
181182
}
182183

183184
// IsAuthorized returns true if current user is authorized to perform this action

app/handlers/admin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func AdvancedSettingsPage() web.HandlerFunc {
3232
Title: "Advanced · Site Settings",
3333
Data: web.Map{
3434
"customCSS": c.Tenant().CustomCSS,
35+
"allowedSchemes": c.Tenant().AllowedSchemes,
3536
},
3637
})
3738
}
@@ -84,6 +85,7 @@ func UpdateAdvancedSettings() web.HandlerFunc {
8485

8586
if err := bus.Dispatch(c, &cmd.UpdateTenantAdvancedSettings{
8687
CustomCSS: action.CustomCSS,
88+
AllowedSchemes: action.AllowedSchemes,
8789
}); err != nil {
8890
return c.Failure(err)
8991
}

app/models/cmd/tenant.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ type UpdateTenantSettings struct {
3535
}
3636

3737
type UpdateTenantAdvancedSettings struct {
38-
CustomCSS string
38+
CustomCSS string
39+
AllowedSchemes string
3940
}
4041

4142
type ActivateTenant struct {

app/models/entity/tenant.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Tenant struct {
1515
IsPrivate bool `json:"isPrivate"`
1616
LogoBlobKey string `json:"logoBlobKey"`
1717
CustomCSS string `json:"-"`
18+
AllowedSchemes string `json:"allowedSchemes"`
1819
IsEmailAuthAllowed bool `json:"isEmailAuthAllowed"`
1920
IsFeedEnabled bool `json:"isFeedEnabled"`
2021
PreventIndexing bool `json:"preventIndexing"`

app/pkg/env/env.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type config struct {
5454
Locale string `env:"LOCALE,default=en"`
5555
JWTSecret string `env:"JWT_SECRET,required"`
5656
PostCreationWithTagsEnabled bool `env:"POST_CREATION_WITH_TAGS_ENABLED,default=false"`
57+
AllowAllowedSchemes bool `env:"ALLOW_ALLOWED_SCHEMES,default=true"`
5758
Paddle struct {
5859
IsSandbox bool `env:"PADDLE_SANDBOX,default=false"`
5960
VendorID string `env:"PADDLE_VENDOR_ID"`

app/pkg/web/renderer.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,19 @@ func (r *Renderer) Render(w io.Writer, statusCode int, props Props, ctx *Context
204204
public["tenant"] = tenant
205205
public["props"] = props.Data
206206
public["settings"] = &Map{
207-
"mode": env.Config.HostMode,
208-
"locale": locale,
209-
"localeDirection": localeDirection,
210-
"environment": env.Config.Environment,
211-
"googleAnalytics": env.Config.GoogleAnalytics,
212-
"domain": env.MultiTenantDomain(),
213-
"hasLegal": env.HasLegal(),
214-
"isBillingEnabled": env.IsBillingEnabled(),
215-
"baseURL": ctx.BaseURL(),
216-
"assetsURL": AssetsURL(ctx, ""),
217-
"oauth": oauthProviders.Result,
218-
"postWithTags": env.Config.PostCreationWithTagsEnabled,
207+
"mode": env.Config.HostMode,
208+
"locale": locale,
209+
"localeDirection": localeDirection,
210+
"environment": env.Config.Environment,
211+
"googleAnalytics": env.Config.GoogleAnalytics,
212+
"domain": env.MultiTenantDomain(),
213+
"hasLegal": env.HasLegal(),
214+
"isBillingEnabled": env.IsBillingEnabled(),
215+
"baseURL": ctx.BaseURL(),
216+
"assetsURL": AssetsURL(ctx, ""),
217+
"oauth": oauthProviders.Result,
218+
"postWithTags": env.Config.PostCreationWithTagsEnabled,
219+
"allowAllowedSchemes": env.Config.AllowAllowedSchemes,
219220
}
220221

221222
if ctx.IsAuthenticated() {

app/pkg/web/testdata/basic.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h2 class="text-display2">Please enable JavaScript</h2>
4545

4646
<script id="server-data" type="application/json">
4747

48-
{"contextID":"CONTEXT_ID","page":"","props":{},"sessionID":"","settings":{"assetsURL":"https://demo.test.fider.io:3000","baseURL":"https://demo.test.fider.io:3000","domain":".test.fider.io","environment":"test","googleAnalytics":"","hasLegal":true,"isBillingEnabled":false,"locale":"en","localeDirection":"ltr","mode":"multi","oauth":[],"postWithTags":true},"tenant":null,"title":"Fider"}
48+
{"contextID":"CONTEXT_ID","page":"","props":{},"sessionID":"","settings":{"allowAllowedSchemes":true,"assetsURL":"https://demo.test.fider.io:3000","baseURL":"https://demo.test.fider.io:3000","domain":".test.fider.io","environment":"test","googleAnalytics":"","hasLegal":true,"isBillingEnabled":false,"locale":"en","localeDirection":"ltr","mode":"multi","oauth":[],"postWithTags":true},"tenant":null,"title":"Fider"}
4949

5050
</script>
5151

app/pkg/web/testdata/canonical.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ <h2 class="text-display2">Please enable JavaScript</h2>
4747

4848
<script id="server-data" type="application/json">
4949

50-
{"contextID":"CONTEXT_ID","page":"","props":{},"sessionID":"","settings":{"assetsURL":"https://demo.test.fider.io:3000","baseURL":"https://demo.test.fider.io:3000","domain":".test.fider.io","environment":"test","googleAnalytics":"","hasLegal":true,"isBillingEnabled":false,"locale":"en","localeDirection":"ltr","mode":"multi","oauth":[],"postWithTags":true},"tenant":null,"title":"Fider"}
50+
{"contextID":"CONTEXT_ID","page":"","props":{},"sessionID":"","settings":{"allowAllowedSchemes":true,"assetsURL":"https://demo.test.fider.io:3000","baseURL":"https://demo.test.fider.io:3000","domain":".test.fider.io","environment":"test","googleAnalytics":"","hasLegal":true,"isBillingEnabled":false,"locale":"en","localeDirection":"ltr","mode":"multi","oauth":[],"postWithTags":true},"tenant":null,"title":"Fider"}
5151

5252
</script>
5353

app/pkg/web/testdata/chunk.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h2 class="text-display2">Please enable JavaScript</h2>
4545

4646
<script id="server-data" type="application/json">
4747

48-
{"contextID":"CONTEXT_ID","page":"Test.page","props":{},"sessionID":"","settings":{"assetsURL":"https://demo.test.fider.io:3000","baseURL":"https://demo.test.fider.io:3000","domain":".test.fider.io","environment":"test","googleAnalytics":"","hasLegal":true,"isBillingEnabled":false,"locale":"en","localeDirection":"ltr","mode":"multi","oauth":[],"postWithTags":true},"tenant":null,"title":"Fider"}
48+
{"contextID":"CONTEXT_ID","page":"Test.page","props":{},"sessionID":"","settings":{"allowAllowedSchemes":true,"assetsURL":"https://demo.test.fider.io:3000","baseURL":"https://demo.test.fider.io:3000","domain":".test.fider.io","environment":"test","googleAnalytics":"","hasLegal":true,"isBillingEnabled":false,"locale":"en","localeDirection":"ltr","mode":"multi","oauth":[],"postWithTags":true},"tenant":null,"title":"Fider"}
4949

5050
</script>
5151

0 commit comments

Comments
 (0)