Skip to content

Commit d0af1de

Browse files
committed
[IMP] add server settings for CORS
- Introduced ServerSettings.vue for managing CORS origins and extension permissions. - Updated settings store to only save keys that were explicitly changed, preventing unintended overwrites of other settings with client-side defaults. - Cleaned up redundant commit hash display and unused data properties in ServerSettings.vue.
1 parent cd5aafe commit d0af1de

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

src/stores/settings.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ interface State {
4444
showYearly: boolean;
4545
useMultidevice: boolean;
4646
requestTimeout: number;
47+
// Server configuration
48+
cors: string;
49+
cors_regex: string;
50+
cors_allow_aw_chrome_extension: boolean;
51+
cors_allow_all_mozilla_extension: boolean;
4752

4853
// Set to true if settings loaded
4954
_loaded: boolean;
@@ -83,6 +88,10 @@ export const useSettingsStore = defineStore('settings', {
8388
showYearly: false,
8489
useMultidevice: false,
8590
requestTimeout: 30,
91+
cors: '',
92+
cors_regex: '',
93+
cors_allow_aw_chrome_extension: true,
94+
cors_allow_all_mozilla_extension: false,
8695

8796
_loaded: false,
8897
}),
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<template lang="pug">
2+
div
3+
h4.mb-3 Security & CORS
4+
5+
b-alert(show variant="info" class="mb-4")
6+
h5.alert-heading Require Restart
7+
p.mb-0 Changing settings in this section requires stopping and restarting the server for the changes to take effect.
8+
9+
b-form-group(label="Fixed CORS origins" label-cols-md=4 description="Configure general CORS origins with exact matches (e.g. http://localhost:8080). Comma-separated.")
10+
b-input(v-model="cors" type="text")
11+
12+
b-form-group(label="Regex CORS origins" label-cols-md=4 description="Configure CORS origins with regular expressions. Useful for browser extensions (e.g. chrome-extension://.* or moz-extension://.*). Comma-separated.")
13+
b-input(v-model="corsregex" type="text")
14+
15+
h5.mt-4 Extensions Shortcuts
16+
b-form-group(label-cols-md=4)
17+
b-form-checkbox(v-model="cors_allow_aw_chrome_extension") Allow ActivityWatch extension (Chrome)
18+
template(#description)
19+
div Chrome extensions use a stable, persistent ID, so the official extension is reliably supported.
20+
21+
b-form-group(label-cols-md=4)
22+
b-form-checkbox(v-model="cors_allow_all_mozilla_extension") Allow all Firefox extensions (DANGEROUS)
23+
template(#description)
24+
div Every version of a Mozilla extension has its own ID to avoid fingerprinting. This is why you must either allow all extensions or manually configure your specific ID.
25+
div.mt-2.text-danger(v-if="cors_allow_all_mozilla_extension")
26+
| ⚠️ DANGEROUS: Not recommended for security. If enabled, any installed extension can access your ActivityWatch data. Use this only if you know what extensions you have and assume full responsibility.
27+
div(v-else)
28+
| Recommended for security. To allow a specific extension safely:
29+
ol.mt-2.mb-1
30+
li Go to <code>about:debugging#/runtime/this-firefox</code> in your browser.
31+
li Look for your extension and copy the <b>Manifest URL</b> (e.g. <code>moz-extension://4b931c07dededdedff152/manifest.json</code>).
32+
li Remove <code>manifest.json</code> from the end (to get <code>moz-extension://4b931c07dededdedff152</code>).
33+
li Paste it into the <b>Regex CORS origins</b> field above (use a comma to separate if not empty).
34+
35+
36+
</template>
37+
38+
<script lang="ts">
39+
import { useSettingsStore } from '~/stores/settings';
40+
41+
export default {
42+
43+
computed: {
44+
cors: {
45+
get() {
46+
return useSettingsStore().cors;
47+
},
48+
set(cors) {
49+
useSettingsStore().update({ cors });
50+
},
51+
},
52+
corsregex: {
53+
get() {
54+
return useSettingsStore().cors_regex;
55+
},
56+
set(cors_regex) {
57+
useSettingsStore().update({ cors_regex });
58+
},
59+
},
60+
cors_allow_aw_chrome_extension: {
61+
get() {
62+
return useSettingsStore().cors_allow_aw_chrome_extension;
63+
},
64+
set(cors_allow_aw_chrome_extension) {
65+
useSettingsStore().update({ cors_allow_aw_chrome_extension });
66+
},
67+
},
68+
cors_allow_all_mozilla_extension: {
69+
get() {
70+
return useSettingsStore().cors_allow_all_mozilla_extension;
71+
},
72+
set(cors_allow_all_mozilla_extension) {
73+
useSettingsStore().update({ cors_allow_all_mozilla_extension });
74+
},
75+
},
76+
},
77+
};
78+
</script>

src/views/settings/Settings.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ div
3737
hr
3838

3939
DeveloperSettings
40+
41+
hr
42+
43+
ServerSettings
4044
</template>
4145

4246
<script lang="ts">
@@ -49,6 +53,7 @@ import ReleaseNotificationSettings from '~/views/settings/ReleaseNotificationSet
4953
import CategorizationSettings from '~/views/settings/CategorizationSettings.vue';
5054
import LandingPageSettings from '~/views/settings/LandingPageSettings.vue';
5155
import DeveloperSettings from '~/views/settings/DeveloperSettings.vue';
56+
import ServerSettings from '~/views/settings/ServerSettings.vue';
5257
import Theme from '~/views/settings/Theme.vue';
5358
import ColorSettings from '~/views/settings/ColorSettings.vue';
5459
import ActivePatternSettings from '~/views/settings/ActivePatternSettings.vue';
@@ -64,6 +69,7 @@ export default {
6469
Theme,
6570
ColorSettings,
6671
DeveloperSettings,
72+
ServerSettings,
6773
ActivePatternSettings,
6874
},
6975
beforeRouteLeave(to, from, next) {

0 commit comments

Comments
 (0)