Skip to content

Commit 208c67b

Browse files
committed
Merge branch 'main' into appendPutNewDocument
2 parents 2dd0789 + 83dad06 commit 208c67b

File tree

13 files changed

+3601
-1086
lines changed

13 files changed

+3601
-1086
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

1818
strategy:
1919
matrix:
20-
node-version: [12.x, 14.x, 16.x]
20+
node-version: [16.x, 18.x]
2121
os: [ubuntu-latest]
2222

2323
steps:
@@ -97,4 +97,4 @@ jobs:
9797
build-args: SOLID_SERVER_VERSION=${{ steps.tagName.outputs.version }}
9898
push: true
9999
tags: ${{ steps.meta.outputs.tags }}
100-
labels: ${{ steps.meta.outputs.labels }}
100+
labels: ${{ steps.meta.outputs.labels }}

lib/acl-checker.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ class ACLChecker {
2828
constructor (resource, options = {}) {
2929
this.resource = resource
3030
this.resourceUrl = new URL(resource)
31-
this.agentOrigin = options.strictOrigin && options.agentOrigin ? rdf.sym(options.agentOrigin) : null
31+
this.agentOrigin = null
32+
try {
33+
if (options.strictOrigin && options.agentOrigin) {
34+
this.agentOrigin = rdf.sym(options.agentOrigin)
35+
}
36+
} catch (e) {
37+
// noop
38+
}
3239
this.fetch = options.fetch
3340
this.fetchGraph = options.fetchGraph
3441
this.trustedOrigins = options.strictOrigin && options.trustedOrigins ? options.trustedOrigins.map(trustedOrigin => rdf.sym(trustedOrigin)) : null

lib/handlers/allow.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ function allow (mode) {
7272
}
7373
}
7474

75-
// check user is owner. Find owner from /.meta
76-
if (resourceUrl.endsWith('.acl') && userId === await ldp.getOwner(req.hostname)) return next()
77-
75+
// check if user is owner. Check isOwner from /.meta
76+
try {
77+
if (resourceUrl.endsWith('.acl') && (await ldp.isOwner(userId, req.hostname))) return next()
78+
} catch (err) {}
7879
const error = req.authError || await req.acl.getError(userId, mode)
7980
debug(`${mode} access denied to ${userId || '(none)'}: ${error.status} - ${error.message}`)
8081
next(error)

lib/handlers/patch.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ async function checkPermission (request, patchObject, resourceExists) {
143143
// Now that we know the details of the patch,
144144
// we might need to perform additional checks.
145145
let modes = []
146-
// acl:default Write is required for create when resource exists
147-
if (resourceExists) modes = ['Write']
148146
const { acl, session: { userId } } = request
149147
// Read access is required for DELETE and WHERE.
150148
// If we would allows users without read access,
@@ -164,7 +162,7 @@ async function checkPermission (request, patchObject, resourceExists) {
164162
if (!allAllowed) {
165163
// check owner with Control
166164
const ldp = request.app.locals.ldp
167-
if (request.path.endsWith('.acl') && userId === await ldp.getOwner(request.hostname)) return Promise.resolve(patchObject)
165+
if (request.path.endsWith('.acl') && await ldp.isOwner(userId, request.hostname)) return Promise.resolve(patchObject)
168166

169167
const errors = await Promise.all(modes.map(mode => acl.getError(userId, mode)))
170168
const error = errors.filter(error => !!error)

lib/header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async function addPermissions (req, res, next) {
128128
getPermissionsFor(acl, null, req),
129129
getPermissionsFor(acl, session.userId, req)
130130
])
131-
if (resource.endsWith('.acl') && userPerms === '' && session.userId === await ldp.getOwner(req.hostname)) userPerms = 'control'
131+
if (resource.endsWith('.acl') && userPerms === '' && await ldp.isOwner(session.userId, req.hostname)) userPerms = 'control'
132132
debug.ACL(`Permissions on ${resource} for ${session.userId || '(none)'}: ${userPerms}`)
133133
debug.ACL(`Permissions on ${resource} for public: ${publicPerms}`)
134134
res.set('WAC-Allow', `user="${userPerms}",public="${publicPerms}"`)

lib/ldp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,16 +454,16 @@ class LDP {
454454
// this is a hack to replace solid:owner, using solid:account in /.meta to avoid NSS migration
455455
// this /.meta has no functionality in actual NSS
456456
// comment https://github.com/solid/node-solid-server/pull/1604#discussion_r652903546
457-
async getOwner (hostname) {
457+
async isOwner (webId, hostname) {
458458
// const ldp = req.app.locals.ldp
459459
const rootUrl = this.resourceMapper.resolveUrl(hostname)
460460
let graph
461461
try {
462462
// TODO check for permission ?? Owner is a MUST
463463
graph = await this.getGraph(rootUrl + '/.meta')
464464
const SOLID = $rdf.Namespace('http://www.w3.org/ns/solid/terms#')
465-
const owner = await graph.any(null, SOLID('account'), $rdf.sym(rootUrl + '/'))
466-
return owner.uri
465+
const owner = await graph.statementsMatching($rdf.sym(webId), SOLID('account'), $rdf.sym(rootUrl + '/'))
466+
return owner.length
467467
} catch (error) {
468468
throw new Error(`Failed to get owner from ${rootUrl}/.meta, got ` + error)
469469
}

0 commit comments

Comments
 (0)