Skip to content

Commit e30a4ef

Browse files
committed
Evil apps with cannot cheat with subdomains anymore
1 parent 7162102 commit e30a4ef

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/requests/consent-request.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ConsentRequest extends AuthRequest {
7272
// Check if is already registered or is data browser
7373
if (request.isUserLoggedIn()) {
7474
if (
75-
(appUrl && appUrl.host.includes(serverUrl.host) && appUrl.protocol === serverUrl.protocol) ||
75+
(appUrl && request.isSubdomain(serverUrl.host, appUrl.host) && appUrl.protocol === serverUrl.protocol) ||
7676
await request.isAppRegistered(req.app.locals.ldp, appOrigin, request.session.subject._id)
7777
) {
7878
request.setUserConsent(appOrigin)
@@ -117,6 +117,17 @@ class ConsentRequest extends AuthRequest {
117117
}
118118
}
119119

120+
isSubdomain (domain, subdomain) {
121+
const domainArr = domain.split('.')
122+
const subdomainArr = subdomain.split('.')
123+
for (let i = 1; i <= domainArr.length; i++) {
124+
if (subdomainArr[subdomainArr.length - i] !== domainArr[domainArr.length - i]) {
125+
return false
126+
}
127+
}
128+
return true
129+
}
130+
120131
setUserConsent (appOrigin) {
121132
if (!this.session.consentedOrigins) {
122133
this.session.consentedOrigins = []

0 commit comments

Comments
 (0)