Skip to content

Commit

Permalink
fix(editor): Prevent Safari users from accessing the frontend over in…
Browse files Browse the repository at this point in the history
…secure contexts
  • Loading branch information
netroy committed Aug 22, 2024
1 parent dc7dc99 commit 321540b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/editor-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@vueuse/components": "^10.11.0",
"@vueuse/core": "^10.11.0",
"axios": "catalog:",
"bowser": "2.11.0",
"chart.js": "^4.4.0",
"codemirror-lang-html-n8n": "^1.0.0",
"dateformat": "^3.0.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,14 +839,14 @@ export const ROLE = {
export const INSECURE_CONNECTION_WARNING = `
<body style="margin-top: 20px; font-family: 'Open Sans', sans-serif; text-align: center;">
<h1 style="font-size: 40px">&#x1F6AB;</h1>
<h2>Your n8n server is configured to use a secure cookie, <br/>however you are visiting this via an insecure URL
<h2>Your n8n server is configured to use a secure cookie, <br/>however you are either visiting this via an insecure URL, or using Safari.
</h2>
<br/>
<div style="font-size: 18px; max-width: 640px; text-align: left; margin: 10px auto">
To fix this, please consider the following options:
<ul>
<li>Setup TLS/HTTPS (<strong>recommended</strong>), or</li>
<li>If you are running this locally, try using <a href="http://localhost:5678">localhost</a> instead</li>
<li>If you are running this locally, and not using Safari, try using <a href="http://localhost:5678">localhost</a> instead</li>
<li>If you prefer to disable this security feature (<strong>not recommended</strong>), set the environment variable <code>N8N_SECURE_COOKIE</code> to <code>false</code></li>
</ul>
</div>
Expand Down
20 changes: 12 additions & 8 deletions packages/editor-ui/src/stores/settings.store.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { computed, ref } from 'vue';
import Bowser from 'bowser';

import * as publicApiApi from '@/api/api-keys';
import * as ldapApi from '@/api/ldap';
import * as settingsApi from '@/api/settings';
Expand All @@ -21,7 +24,6 @@ import { makeRestApiRequest } from '@/utils/apiUtils';
import { useTitleChange } from '@/composables/useTitleChange';
import { useToast } from '@/composables/useToast';
import { i18n } from '@/plugins/i18n';
import { computed, ref } from 'vue';

export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
const initialized = ref(false);
Expand Down Expand Up @@ -189,13 +191,15 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
useRootStore().setVersionCli(settings.value.versionCli);
}

if (
settings.value.authCookie.secure &&
location.protocol === 'http:' &&
!['localhost', '127.0.0.1'].includes(location.hostname)
) {
document.write(INSECURE_CONNECTION_WARNING);
return;
if (settings.value.authCookie.secure) {
const { browser } = Bowser.parse(navigator.userAgent);
if (
location.protocol === 'http:' &&
(!['localhost', '127.0.0.1'].includes(location.hostname) || browser.name === 'Safari')
) {
document.write(INSECURE_CONNECTION_WARNING);
return;
}
}

const isV1BannerDismissedPermanently = (settings.value.banners?.dismissed || []).includes('V1');
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 321540b

Please sign in to comment.