Skip to content

Commit 8000ad1

Browse files
authored
Merge pull request #6103 from Countly/ar2rsawseen/master
[SER-136] Add ability to allow multiple CORS for an app
2 parents 7388195 + 55b9a65 commit 8000ad1

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Version 25.03.x
22

3+
Features:
4+
- Add ability to allow multiple CORS per app for web apps
5+
36
Dependencies:
47
- Bump body-parser from 1.20.3 to 2.2.0
58
- Bump moment-timezone from 0.5.47 to 0.5.48

api/utils/common.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,12 @@ common.returnMessage = function(params, returnCode, message, heads, noResult = f
16091609
headers[i] = heads[i];
16101610
}
16111611
}
1612+
if (params && params.app && params.app.plugins && params.app.plugins.allow_access_control_origin && params.req.headers && params.req.headers.origin) {
1613+
var cors_headers = (params.app.plugins.allow_access_control_origin || "").replace(/\r\n|\r|\n/g, "\n").split("\n");
1614+
if (cors_headers.includes(params.req.headers.origin)) {
1615+
headers['Access-Control-Allow-Origin'] = params.req.headers.origin;
1616+
}
1617+
}
16121618
if (params && params.res && params.res.writeHead && !params.blockResponses) {
16131619
if (!params.res.finished) {
16141620
params.res.writeHead(returnCode, headers);
@@ -1678,6 +1684,13 @@ common.returnOutput = function(params, output, noescape, heads) {
16781684
headers[i] = heads[i];
16791685
}
16801686
}
1687+
1688+
if (params && params.app && params.app.plugins && params.app.plugins.allow_access_control_origin && params.req.headers && params.req.headers.origin) {
1689+
var cors_headers = (params.app.plugins.allow_access_control_origin || "").replace(/\r\n|\r|\n/g, "\n").split("\n");
1690+
if (cors_headers.includes(params.req.headers.origin)) {
1691+
headers['Access-Control-Allow-Origin'] = params.req.headers.origin;
1692+
}
1693+
}
16811694
if (params && params.res && params.res.writeHead && !params.blockResponses) {
16821695
if (!params.res.finished) {
16831696
params.res.writeHead(200, headers);

plugins/plugins/frontend/public/javascripts/countly.views.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,12 @@
13161316
});
13171317
}
13181318

1319+
if (app.configurationsView) {
1320+
app.configurationsView.registerLabel("allow_access_control_origin", jQuery.i18n.map["configs.allow_access_control_origin"]);
1321+
}
1322+
1323+
app.addAppManagementInput("allow_access_control_origin", jQuery.i18n.map["configs.access_control_origin"], {"allow_access_control_origin": {input: "el-input", attrs: {type: "textarea", rows: 5}}});
1324+
13191325
app.route('/account-settings', 'account-settings', function() {
13201326
this.renderWhenReady(getAccountView());
13211327
});

plugins/plugins/frontend/public/localization/plugins.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ configs.new-password = New Password
144144
configs.confirmation = Confirm new password
145145
configs.password-specification-1 = Use a password at least 15 letters long or at least
146146
configs.password-specification-2 = 8 characters long with mixed letters and numbers.
147+
configs.access_control_origin = Access-Control-Origin
148+
configs.allow_access_control_origin = Allow Access-Control-Origin by listing separate origin (including https://) per line
147149

148150
configs.api.description = Main API settings
149151
configs.api.batch = Batch processing

0 commit comments

Comments
 (0)