Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

✨ Adds optional allowInsecure prop for widgets to skip cert verification (#2327)

Alicia Sykes3228c7b7c78f
diff --git a/docs/configuring.md b/docs/configuring.md
index f943306f..29427262 100644
--- a/docs/configuring.md
+++ b/docs/configuring.md
@@ -315,6 +315,7 @@ For more info, see the **[Authentication Docs](/docs/authentication.md)**
**`options`** | `object` | _Optional_ | Some widgets accept either optional or required additional options. Again, see the [Widget Docs](/docs/widgets.md) for full list of options
**`updateInterval`** | `number` | _Optional_ | You can keep a widget constantly updated by specifying an update interval, in seconds. See [Continuous Updates Docs](/docs/widgets.md#continuous-updates) for more info
**`useProxy`** | `boolean` | _Optional_ | Some widgets make API requests to services that are not CORS-enabled. For these instances, you will need to route requests through a proxy, Dashy has a built in CORS-proxy, which you can use by setting this option to `true`. Defaults to `false`. See the [Proxying Requests Docs](/docs/widgets.md#proxying-requests) for more info
+**`allowInsecure`** | `boolean` | _Optional_ | Skip TLS certificate verification for this widget's proxied requests, for targets with a self-signed or mismatched certificate. Defaults to `false`. See the [Ignoring Certificate Errors Docs](/docs/widgets.md#ignoring-certificate-errors) for more info
**`timeout`** | `number` | _Optional_ | Request timeout in milliseconds, defaults to Β½ a second (`500`)
**`ignoreErrors`** | `boolean` | _Optional_ | Prevent an error message being displayed, if a network request or something else fails. Useful for false-positives
**`label`** | `string` | _Optional_ | Add custom label to a given widget. Useful for identification, if there are multiple of the same type of widget in a single section
diff --git a/docs/security.md b/docs/security.md
index 9cb23c4b..8319ece7 100644
--- a/docs/security.md
+++ b/docs/security.md
@@ -196,7 +196,7 @@ These are reported regularly, usually by automated scanners. Each has been check
|---|---|
| Ping and status checks allow command injection | The host goes to pingman, which runs `spawn('ping', ...)` with no shell, so `;`, `|`, `$()` and backticks are inert. It is one trailing argument, so no extra flags either. |
| The CORS proxy can read arbitrary environment variables | Only `DASHY_`, `VITE_APP_` prefixes are read. The client `VITE_APP_` vars are already in the bundle, and `DASHY_` is opt-in. Unprefixed secrets stay unreachable. |
-| `enableInsecure` disables TLS certificate verification | Opt-in per status check, for internal services with self-signed certs, and it only affects that one request. Leave `statusCheckAllowInsecure` unset to keep verification on. |
+| `enableInsecure` disables TLS certificate verification | Opt-in per status check, for internal services with self-signed certs, and it only affects that one request. Leave `statusCheckAllowInsecure` unset to keep verification on. The equivalent for widgets is `allowInsecure`, which is also opt-in and per-widget. |
| OIDC does not pin the JWT algorithm (alg confusion or `none`) | Verification uses a remote JWKS, so jose rejects none and symmetric algorithms. The issuer and group claims come from a signature-verified token, so a user cannot forge them. |
| `yaml.load()` allows code execution on parse | In js-yaml 4.x (we use `^4.2.0`) `load` is the safe loader. It does not instantiate custom types, so parsing a config file cannot execute code. |
| Prototype pollution via the config API's Object.assign | `Object.assign` is a shallow set, so a `__proto__` key reparents only that object and is dropped on dump. `Object.prototype` is untouched, and the API is admin-gated behind `ENABLE_API`. |
diff --git a/docs/widgets.md b/docs/widgets.md
index 5e0eb7e6..b0a56931 100644
--- a/docs/widgets.md
+++ b/docs/widgets.md
@@ -103,6 +103,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a
- [Widget Usage Guide](#widget-usage-guide)
- [Continuous Updates](#continuous-updates)
- [Proxying Requests](#proxying-requests)
+ - [Ignoring Certificate Errors](#ignoring-certificate-errors)
- [Handling Secrets](#handling-secrets)
- [Setting Timeout](#setting-timeout)
- [Adding Labels](#adding-labels)
@@ -3588,6 +3589,29 @@ Vary: Origin
---
+### Ignoring Certificate Errors
+
+If you're calling a local service with a self-signed certificate, then you'll get an error (like `UNABLE_TO_VERIFY_LEAF_SIGNATURE` or `ERR_TLS_CERT_ALTNAME_INVALID`).
+
+If you trust the host, you can choose to skip certificate verification for that widget, by setting `allowInsecure: true`, this will fix your issue.
+
+Note that this only works if `useProxy: true` is also set, since browsers don't allow you to skip cert checks.
+
+
+```yaml
+widgets:
+- type: customapi
+ useProxy: true
+ allowInsecure: true
+ options:
+ url: https://tool.ad.local/api/status
+```
+
+> [!WARNING]
+> With verification off, nothing checks that you're talking to the server you think you are. Any headers you've set on the widget (API keys, basic auth) are sent over that unverified connection. Prefer fixing the certificate, or adding your CA with `NODE_EXTRA_CA_CERTS`, where you can.
+
+---
+
### Handling Secrets
Some widgets require you to pass potentially sensitive info such as API keys. The `conf.yml` is not ideal for this, as it's stored in plaintext. Instead, for secrets you should use environment variables.
diff --git a/services/endpoints/cors-proxy.js b/services/endpoints/cors-proxy.js
index fdf19056..aac59c0d 100644
--- a/services/endpoints/cors-proxy.js
+++ b/services/endpoints/cors-proxy.js
@@ -81,6 +81,11 @@ const handler = (req, res) => {
validateUrl: validateTargetUrl,
};
+ // Opt-in to skipping TLS verification, for targets with a self-signed or mismatched cert
+ if (req.header('Allow-Insecure') === 'true') {
+ requestConfig.httpsAgent = { rejectUnauthorized: false };
+ }
+
// Make the request, and respond with result
const send = (status, body) => {
if (res.headersSent) return;
diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json
index 4277152d..ab6ee3d3 100644
--- a/src/assets/locales/en.json
+++ b/src/assets/locales/en.json
@@ -387,6 +387,7 @@
"update-interval-label": "Update Interval (seconds)",
"timeout-label": "Timeout (ms)",
"use-proxy-label": "Use Proxy",
+ "allow-insecure-label": "Allow Insecure",
"ignore-errors-label": "Ignore Errors",
"options-heading": "Widget Options",
"add-option-btn": "Add Option",
diff --git a/src/components/InteractiveEditor/EditWidget.vue b/src/components/InteractiveEditor/EditWidget.vue
index 2b9a62a7..874f669e 100644
--- a/src/components/InteractiveEditor/EditWidget.vue
+++ b/src/components/InteractiveEditor/EditWidget.vue
@@ -39,6 +39,12 @@
:options="boolRadioOptions"
:initialOption="form.useProxy"
/>
+ <Radio
+ v-model="form.allowInsecure"
+ :label="$t('interactive-editor.edit-widget.allow-insecure-label')"
+ :options="boolRadioOptions"
+ :initialOption="form.allowInsecure"
+ />
<Radio
v-model="form.ignoreErrors"
:label="$t('interactive-editor.edit-widget.ignore-errors-label')"
@@ -88,6 +94,7 @@ const emptyForm = () => ({
updateInterval: '',
timeout: '',
useProxy: '',
+ allowInsecure: '',
ignoreErrors: '',
});
@@ -139,6 +146,7 @@ export default {
updateInterval: widget.updateInterval ?? '',
timeout: widget.timeout ?? '',
useProxy: widget.useProxy === undefined ? '' : String(widget.useProxy),
+ allowInsecure: widget.allowInsecure === undefined ? '' : String(widget.allowInsecure),
ignoreErrors: widget.ignoreErrors === undefined ? '' : String(widget.ignoreErrors),
};
this.optionRows = Object.entries(widget.options || {}).map(([key, value]) => ({
@@ -168,6 +176,8 @@ export default {
}
if (this.form.useProxy === 'true') widget.useProxy = true;
else if (this.form.useProxy === 'false') widget.useProxy = false;
+ if (this.form.allowInsecure === 'true') widget.allowInsecure = true;
+ else if (this.form.allowInsecure === 'false') widget.allowInsecure = false;
if (this.form.ignoreErrors === 'true') widget.ignoreErrors = true;
else if (this.form.ignoreErrors === 'false') widget.ignoreErrors = false;
const options = {};
diff --git a/src/components/Widgets/GlCompactMetrics.vue b/src/components/Widgets/GlCompactMetrics.vue
index bd9e86eb..9908d933 100644
--- a/src/components/Widgets/GlCompactMetrics.vue
+++ b/src/components/Widgets/GlCompactMetrics.vue
@@ -182,7 +182,7 @@ export default {
if (this.useProxy) {
return {
url: this.proxyReqEndpoint,
- headers: { 'Target-URL': endpoint, CustomHeaders: JSON.stringify(headers) },
+ headers: this.proxyHeaders(endpoint, headers),
};
}
return { url: endpoint, headers };
diff --git a/src/components/Widgets/SynologyDownload.vue b/src/components/Widgets/SynologyDownload.vue
index caf9958b..20f2d6b2 100644
--- a/src/components/Widgets/SynologyDownload.vue
+++ b/src/components/Widgets/SynologyDownload.vue
@@ -73,7 +73,7 @@ export default {
request({
method: 'GET',
url: this.proxyReqEndpoint,
- headers: { 'Target-URL': this.endpointLogin },
+ headers: this.proxyHeaders(this.endpointLogin),
})
.then(this.processLogin);
},
@@ -81,7 +81,7 @@ export default {
request({
method: 'GET',
url: this.proxyReqEndpoint,
- headers: { 'Target-URL': this.endpointTasks },
+ headers: this.proxyHeaders(this.endpointTasks),
})
.then(this.processTask);
},
@@ -89,7 +89,7 @@ export default {
request({
method: 'GET',
url: this.proxyReqEndpoint,
- headers: { 'Target-URL': this.endpointLogout },
+ headers: this.proxyHeaders(this.endpointLogout),
});
},
fetchData() {
diff --git a/src/components/Widgets/WidgetBase.vue b/src/components/Widgets/WidgetBase.vue
index 34144e68..b3d83213 100644
--- a/src/components/Widgets/WidgetBase.vue
+++ b/src/components/Widgets/WidgetBase.vue
@@ -189,10 +189,11 @@ export default {
const ignoreErrors = this.widget.ignoreErrors || false;
const label = this.widget.label || null;
const useProxy = this.appConfig.widgetsAlwaysUseProxy || !!this.widget.useProxy;
+ const allowInsecure = !!this.widget.allowInsecure;
const updateInterval = this.widget.updateInterval !== undefined
? this.widget.updateInterval : null;
return {
- timeout, ignoreErrors, label, useProxy, updateInterval, ...options,
+ timeout, ignoreErrors, label, useProxy, allowInsecure, updateInterval, ...options,
};
},
/* A unique string to reference the widget by */
diff --git a/src/mixins/WidgetMixin.js b/src/mixins/WidgetMixin.js
index 4346c967..2a79c026 100644
--- a/src/mixins/WidgetMixin.js
+++ b/src/mixins/WidgetMixin.js
@@ -43,6 +43,10 @@ const WidgetMixin = {
useProxy() {
return this.options.useProxy || this.overrideProxyChoice;
},
+ /* Skip TLS verification on proxied requests, for self-signed or mismatched certs */
+ allowInsecure() {
+ return !!this.options.allowInsecure;
+ },
requestTimeout() {
return this.options.timeout || this.defaultTimeout;
},
@@ -103,6 +107,14 @@ const WidgetMixin = {
content, html,
};
},
+ /* Builds the headers which tell the CORS proxy where, and how, to make the request */
+ proxyHeaders(endpoint, customHeaders = null) {
+ return {
+ 'Target-URL': endpoint,
+ CustomHeaders: JSON.stringify(customHeaders),
+ ...(this.allowInsecure ? { 'Allow-Insecure': 'true' } : {}),
+ };
+ },
/* Makes data request, returns promise */
makeRequest(endpoint, options, protocol, body) {
// Request Options
@@ -111,7 +123,7 @@ const WidgetMixin = {
const data = JSON.stringify(body || {});
const CustomHeaders = options || null;
const headers = this.useProxy
- ? { 'Target-URL': endpoint, CustomHeaders: JSON.stringify(CustomHeaders) } : CustomHeaders;
+ ? this.proxyHeaders(endpoint, CustomHeaders) : CustomHeaders;
const requestConfig = {
method, url, headers, data, timeout: this.requestTimeout,
};
@@ -153,6 +165,12 @@ const WidgetMixin = {
return `Upstream returned ${upstream.status}${tail}.`;
}
if (upstream.type === 'upstream_error') {
+ // Node TLS failures which the user can opt out of, with `allowInsecure`
+ const TLS_ERROR_CODE = /^(?:ERR_TLS_|UNABLE_TO_|SELF_SIGNED_|DEPTH_ZERO_|CERT_)/;
+ if (!this.allowInsecure && TLS_ERROR_CODE.test(upstream.code || '')) {
+ return `TLS certificate could not be verified (${upstream.code}). `
+ + 'If you trust this host, set `allowInsecure: true` on the widget.';
+ }
return `Could not reach target server${upstream.code ? ` (${upstream.code})` : ''}.`;
}
}
diff --git a/src/utils/config/ConfigSchema.json b/src/utils/config/ConfigSchema.json
index 6239dc23..1b951f1d 100644
--- a/src/utils/config/ConfigSchema.json
+++ b/src/utils/config/ConfigSchema.json
@@ -1493,6 +1493,11 @@
"type": "boolean",
"description": "If set to true, request will be proxied through the backend. Requires the Node server to be running"
},
+ "allowInsecure": {
+ "title": "Allow Insecure?",
+ "type": "boolean",
+ "description": "If set to true, TLS certificate errors on the target will be ignored. Only applies to proxied requests, so also requires useProxy"
+ },
"options": {
"title": "Widget Options",
"type": "object",
diff --git a/tests/components/customapi.test.js b/tests/components/customapi.test.js
index 17014693..86ac033a 100644
--- a/tests/components/customapi.test.js
+++ b/tests/components/customapi.test.js
@@ -3,6 +3,7 @@ import {
} from 'vitest';
import { shallowMount, flushPromises } from '@vue/test-utils';
import CustomApi from '@/components/Widgets/CustomApi.vue';
+import request from '@/utils/request';
const response = {
name: 'dashy',
@@ -92,6 +93,22 @@ describe('CustomApi widget', () => {
});
});
+ describe('proxied requests', () => {
+ beforeEach(() => request.mockClear());
+
+ it('sends the Allow-Insecure header when allowInsecure is set', async () => {
+ wrapper = mountWidget({ url: 'https://example.com', useProxy: true, allowInsecure: true });
+ await flushPromises();
+ expect(request.mock.calls[0][0].headers['Allow-Insecure']).toBe('true');
+ });
+
+ it('omits the Allow-Insecure header by default', async () => {
+ wrapper = mountWidget({ url: 'https://example.com', useProxy: true });
+ await flushPromises();
+ expect(request.mock.calls[0][0].headers).not.toHaveProperty('Allow-Insecure');
+ });
+ });
+
describe('updateInterval', () => {
it('defaults to 10s', () => {
wrapper = mountWidget({ url: 'https://example.com' });
diff --git a/tests/server/cors-proxy.test.js b/tests/server/cors-proxy.test.js
index bb3db148..003afb89 100644
--- a/tests/server/cors-proxy.test.js
+++ b/tests/server/cors-proxy.test.js
@@ -165,6 +165,17 @@ describe('CORS proxy error classification', () => {
expect(res.body.error.type).toBe('upstream_error');
});
+ it('does not forward the Allow-Insecure control header to the target', async () => {
+ let received = null;
+ handler = (req, res) => { received = req.headers; res.end('{}'); };
+ const res = await request(app)
+ .get('/cors-proxy')
+ .set('Target-URL', targetUrl)
+ .set('Allow-Insecure', 'true');
+ expect(res.status).toBe(200);
+ expect(received['allow-insecure']).toBeUndefined();
+ });
+
it('blocks a redirect to a metadata host (does not follow it)', async () => {
handler = (req, res) => {
res.statusCode = 302;