Skip to content

Commit 97cff8a

Browse files
committed
fix: add config allowed origins
1 parent 395b033 commit 97cff8a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

api/src/setting/services/setting.service.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,23 @@ describe('SettingService', () => {
166166
});
167167
expect(result).toEqual(
168168
new Set([
169+
'*',
169170
'https://example.com',
170171
'https://test.com',
171172
'https://another.com',
172173
]),
173174
);
174175
});
175176

176-
it('should return an empty set if no settings are found', async () => {
177+
it('should return the config allowed cors only if no settings are found', async () => {
177178
jest.spyOn(settingService, 'find').mockResolvedValue([]);
178179

179180
const result = await settingService.getAllowedOrigins();
180181

181182
expect(settingService.find).toHaveBeenCalledWith({
182183
label: 'allowed_domains',
183184
});
184-
expect(result).toEqual(new Set());
185+
expect(result).toEqual(new Set(['*']));
185186
});
186187

187188
it('should handle settings with empty values', async () => {
@@ -197,7 +198,7 @@ describe('SettingService', () => {
197198
expect(settingService.find).toHaveBeenCalledWith({
198199
label: 'allowed_domains',
199200
});
200-
expect(result).toEqual(new Set(['https://example.com']));
201+
expect(result).toEqual(new Set(['*', 'https://example.com']));
201202
});
202203
});
203204
});

api/src/setting/services/setting.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,16 @@ export class SettingService extends BaseService<Setting> {
142142
label: 'allowed_domains',
143143
})) as TextSetting[];
144144

145-
const uniqueOrigins = new Set(
146-
settings.flatMap((setting) =>
147-
setting.value.split(',').filter((o) => !!o),
148-
),
145+
const allowedDomains = settings.flatMap((setting) =>
146+
setting.value.split(',').filter((o) => !!o),
149147
);
150148

149+
const uniqueOrigins = new Set([
150+
...config.security.cors.allowOrigins,
151+
...config.sockets.onlyAllowOrigins,
152+
...allowedDomains,
153+
]);
154+
151155
return uniqueOrigins;
152156
}
153157

0 commit comments

Comments
 (0)