Skip to content

Commit 0339003

Browse files
authored
Merge pull request #1140 from michielbdejong/redo-1118
Redo #1118
2 parents 46b860f + 5980d75 commit 0339003

File tree

16 files changed

+1583
-68
lines changed

16 files changed

+1583
-68
lines changed

lib/acl-checker.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ class ACLChecker {
1616
constructor (resource, options = {}) {
1717
this.resource = resource
1818
this.resourceUrl = new URL(resource)
19-
this.agentOrigin = options.agentOrigin
19+
this.agentOrigin = options.strictOrigin && options.agentOrigin ? rdf.sym(options.agentOrigin) : null
2020
this.fetch = options.fetch
2121
this.fetchGraph = options.fetchGraph
22-
this.strictOrigin = options.strictOrigin
23-
this.trustedOrigins = options.trustedOrigins
22+
this.trustedOrigins = options.strictOrigin && options.trustedOrigins ? options.trustedOrigins.map(trustedOrigin => rdf.sym(trustedOrigin)) : null
2423
this.suffix = options.suffix || DEFAULT_ACL_SUFFIX
2524
this.aclCached = {}
2625
this.messagesCached = {}
@@ -56,17 +55,14 @@ class ACLChecker {
5655
const aclFile = rdf.sym(acl.acl)
5756
const agent = user ? rdf.sym(user) : null
5857
const modes = [ACL(mode)]
59-
const agentOrigin = this.agentOrigin ? rdf.sym(this.agentOrigin) : null
60-
const trustedOrigins = this.trustedOrigins ? this.trustedOrigins.map(trustedOrigin => rdf.sym(trustedOrigin)) : null
58+
const agentOrigin = this.agentOrigin
59+
const trustedOrigins = this.trustedOrigins
6160
const accessDenied = aclCheck.accessDenied(acl.graph, resource, directory, aclFile, agent, modes, agentOrigin, trustedOrigins)
62-
if (accessDenied && this.agentOrigin && this.resourceUrl.origin !== this.agentOrigin) {
63-
this.messagesCached[cacheKey].push(HTTPError(403, accessDenied))
64-
} else if (accessDenied && user) {
61+
62+
if (accessDenied && user) {
6563
this.messagesCached[cacheKey].push(HTTPError(403, accessDenied))
66-
} else if (accessDenied && !user) {
67-
this.messagesCached[cacheKey].push(HTTPError(401, 'Unauthenticated'))
6864
} else if (accessDenied) {
69-
this.messagesCached[cacheKey].push(HTTPError(401, accessDenied))
65+
this.messagesCached[cacheKey].push(HTTPError(401, 'Unauthenticated'))
7066
}
7167
this.aclCached[cacheKey] = Promise.resolve(!accessDenied)
7268
return this.aclCached[cacheKey]

lib/create-app.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,27 @@ function initWebId (argv, app, ldp) {
212212
// without permission by including the credentials set by the Solid server.
213213
app.use((req, res, next) => {
214214
const origin = req.get('origin')
215-
const trustedOrigins = argv.trustedOrigins
215+
const trustedOrigins = ldp.getTrustedOrigins(req)
216216
const userId = req.session.userId
217217
// Exception: allow logout requests from all third-party apps
218218
// such that OIDC client can log out via cookie auth
219219
// TODO: remove this exception when OIDC clients
220220
// use Bearer token to authenticate instead of cookie
221221
// (https://github.com/solid/node-solid-server/pull/835#issuecomment-426429003)
222-
if (!argv.host.allowsSessionFor(userId, origin, trustedOrigins) && !isLogoutRequest(req)) {
222+
//
223+
// Authentication cookies are an optimization:
224+
// instead of going through the process of
225+
// fully validating authentication on every request,
226+
// we go through this process once,
227+
// and store its successful result in a cookie
228+
// that will be reused upon the next request.
229+
// However, that cookie can then be sent by any server,
230+
// even servers that have not gone through the proper authentication mechanism.
231+
// However, if trusted origins are enabled,
232+
// then any origin is allowed to take the shortcut route,
233+
// since malicious origins will be banned at the ACL checking phase.
234+
// https://github.com/solid/node-solid-server/issues/1117
235+
if (!argv.strictOrigin && !argv.host.allowsSessionFor(userId, origin, trustedOrigins) && !isLogoutRequest(req)) {
223236
debug.authentication(`Rejecting session for ${userId} from ${origin}`)
224237
// Destroy session data
225238
delete req.session.userId

package-lock.json

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "solid-server",
33
"description": "Solid server on top of the file-system",
4-
"version": "5.0.0-beta.9",
4+
"version": "5.0.0-beta.8",
55
"author": {
66
"name": "Tim Berners-Lee",
77
"email": "[email protected]"

0 commit comments

Comments
 (0)