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

feat: add allowedIpRanges widgets config #833

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions changelog.d/833.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds widgets config (`allowedIpRanges`) option to control which IPs are allowed to access widgets.
1 change: 1 addition & 0 deletions config.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ listeners:
#widgets:
# # (Optional) EXPERIMENTAL support for complimentary widgets
# addToAdminRooms: false
# allowedIpRanges: []
# disallowedIpRanges:
# - 127.0.0.0/8
# - 10.0.0.0/8
Expand Down
6 changes: 5 additions & 1 deletion docs/advanced/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ widgets:
# - 2001:db8::/32
# - ff00::/8
# - fec0::/10
# allowedIpRanges: []
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we would put in some examples of values here?

publicUrl: https://example.com/widgetapi/v1/static
branding:
widgetTitle: Hookshot Configuration
Expand All @@ -56,7 +57,10 @@ When `addOnInvite` is true, the bridge will add a widget to rooms when the bot i
`disallowedIpRanges` describes which IP ranges should be disallowed when resolving homeserver IP addresses (for security reasons).
Unless you know what you are doing, it is recommended to not include this key. The default blocked IPs are listed above for your convenience.

`publicUrl` should be set to the publicly reachable address for the widget `public` content. By default, Hookshot hosts this content on the
`allowedIpRanges` describes which IP ranges should be allowed when resolving homeserver IP addresses even if they are in `disallowedIpRanges`.
This allows specific sub-ranges of `disallowedIpRanges` to be used without having to carefully construct the ranges that still should be disallowed.

`publicUrl` should be set to the publicly reachable address for the widget `public` content. By default, hookshot hosts this content on the
`widgets` listener under `/widgetapi/v1/static`.

`branding` allows you to change the strings used for various bits of widget UI. At the moment you can:
Expand Down
1 change: 1 addition & 0 deletions helm/hookshot/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ hookshot:
# (Optional) EXPERIMENTAL support for complimentary widgets
#
# addToAdminRooms: false
# allowedIpRanges: []
# disallowedIpRanges:
# - 127.0.0.0/8
# - 10.0.0.0/8
Expand Down
1 change: 1 addition & 0 deletions src/Widgets/BridgeWidgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class BridgeWidgetApi extends ProvisioningApi {
expressApp,
widgetTokenPrefix: "hookshot_",
disallowedIpRanges: config.widgets?.disallowedIpRanges,
allowedIpRanges: config.widgets?.allowedIpRanges,
openIdOverride: config.widgets?.openIdOverrides,
});

Expand Down
7 changes: 7 additions & 0 deletions src/config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ interface BridgeWidgetConfigYAML {
addOnInvite?: boolean;
};
disallowedIpRanges?: string[];
allowedIpRanges?: string[];
branding?: {
widgetTitle: string,
}
Expand All @@ -357,6 +358,8 @@ export class BridgeWidgetConfig {
addOnInvite?: boolean;
};
public readonly disallowedIpRanges?: string[];
public readonly allowedIpRanges?: string[];

public readonly branding: {
widgetTitle: string,
}
Expand All @@ -366,10 +369,14 @@ export class BridgeWidgetConfig {
constructor(yaml: BridgeWidgetConfigYAML) {
this.addToAdminRooms = yaml.addToAdminRooms || false;
this.disallowedIpRanges = yaml.disallowedIpRanges;
this.allowedIpRanges = yaml.allowedIpRanges;
this.roomSetupWidget = yaml.roomSetupWidget;
if (yaml.disallowedIpRanges !== undefined && (!Array.isArray(yaml.disallowedIpRanges) || !yaml.disallowedIpRanges.every(s => typeof s === "string"))) {
throw new ConfigError("widgets.disallowedIpRanges", "must be a string array");
}
if (yaml.allowedIpRanges !== undefined && (!Array.isArray(yaml.allowedIpRanges) || !yaml.allowedIpRanges.every(s => typeof s === "string"))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

N.B. An empty array would skip this, would we allow empty values for allowedIpRanges (effectively blocking the feature entirely, seems a bit pointless :) )

throw new ConfigError("widgets.allowedIpRanges", "must be a string array");
}
try {
this.parsedPublicUrl = makePrefixedUrl(yaml.publicUrl)
this.publicUrl = () => { return this.parsedPublicUrl.href; }
Expand Down
1 change: 1 addition & 0 deletions src/config/Defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const DefaultConfigRoot: BridgeConfigRoot = {
roomSetupWidget: {
addOnInvite: false,
},
allowedIpRanges: [],
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we want this to actually show up as a default, because the default value would block everything currently :)

disallowedIpRanges: DefaultDisallowedIpRanges,
branding: {
widgetTitle: "Hookshot Configuration"
Expand Down
Loading