Skip to content

Commit 0170a22

Browse files
committed
Allow cookies from all subdomains.
1 parent c7ee4aa commit 0170a22

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

lib/models/solid-host.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ class SolidHost {
7272
allowsSessionFor (userId, origin) {
7373
// Allow no user or an empty origin
7474
if (!userId || !origin) return true
75-
// Allow the server's main domain
76-
if (origin === this.serverUri) return true
77-
// Allow the user's subdomain
78-
const userIdHost = userId.replace(/([^:/])\/.*/, '$1')
79-
if (origin === userIdHost) return true
80-
// Disallow everything else
75+
// Allow the server and subdomains
76+
const originHost = getHostName(origin)
77+
const serverHost = getHostName(this.serverUri)
78+
if (originHost === serverHost) return true
79+
if (originHost.endsWith('.' + serverHost)) return true
80+
// Allow the user's own domain
81+
const userHost = getHostName(userId)
82+
if (originHost === userHost) return true
8183
return false
8284
}
8385

@@ -109,4 +111,9 @@ class SolidHost {
109111
}
110112
}
111113

114+
function getHostName (url) {
115+
const match = url.match(/^\w+:\/*([^/]+)/)
116+
return match ? match[1] : ''
117+
}
118+
112119
module.exports = SolidHost

test/unit/solid-host-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ describe('SolidHost', () => {
5555
})
5656

5757
it('should allow a userId with empty origin', () => {
58-
expect(host.allowsSessionFor('https://user.test.local/profile/card#me', '')).to.be.true
58+
expect(host.allowsSessionFor('https://user.own/profile/card#me', '')).to.be.true
5959
})
6060

6161
it('should allow a userId with the user subdomain as origin', () => {
62-
expect(host.allowsSessionFor('https://user.test.local/profile/card#me', 'https://user.test.local')).to.be.true
62+
expect(host.allowsSessionFor('https://user.own/profile/card#me', 'https://user.own')).to.be.true
6363
})
6464

65-
it('should disallow a userId with another subdomain as origin', () => {
66-
expect(host.allowsSessionFor('https://user.test.local/profile/card#me', 'https://other.test.local')).to.be.false
65+
it('should allow a userId with the server domain as origin', () => {
66+
expect(host.allowsSessionFor('https://user.own/profile/card#me', 'https://test.local')).to.be.true
6767
})
6868

69-
it('should allow a userId with the server domain as origin', () => {
70-
expect(host.allowsSessionFor('https://user.test.local/profile/card#me', 'https://test.local')).to.be.true
69+
it('should allow a userId with a server subdomain as origin', () => {
70+
expect(host.allowsSessionFor('https://user.own/profile/card#me', 'https://other.test.local')).to.be.true
7171
})
7272

7373
it('should disallow a userId from a different domain', () => {
74-
expect(host.allowsSessionFor('https://user.test.local/profile/card#me', 'https://other.remote')).to.be.false
74+
expect(host.allowsSessionFor('https://user.own/profile/card#me', 'https://other.remote')).to.be.false
7575
})
7676
})
7777

0 commit comments

Comments
 (0)