Skip to content

Commit 91ec389

Browse files
authored
Merge pull request #16 from solid/fix/origin-public
Disregard origin for public resources
2 parents 93cad8b + 5f8d5c7 commit 91ec389

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/acl-check.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ function modesAllowed (kb, doc, directory, aclDoc, agent, origin, trustedOrigins
7171

7272
function agentOrGroupOK (auth, agent) {
7373
log(` Checking auth ${auth} with agent ${agent}`)
74-
if (kb.holds(auth, ACL('agentClass'), FOAF('Agent'), aclDoc)) {
75-
log(` Agent or group: Ok, its public.`)
76-
return true
77-
}
7874
if (!agent) {
7975
log(` Agent or group: Fail: not public and not logged on.`)
8076
return false
@@ -101,8 +97,12 @@ function modesAllowed (kb, doc, directory, aclDoc, agent, origin, trustedOrigins
10197
}
10298

10399
function agentAndAppFail (auth) {
100+
if (kb.holds(auth, ACL('agentClass'), FOAF('Agent'), aclDoc)) {
101+
log(` Agent or group: Ok, its public.`)
102+
return false
103+
}
104104
if (!agentOrGroupOK(auth, agent)) {
105-
log(' The agent/group/public check fails')
105+
log(' The agent/group check fails')
106106
return 'User Unauthorized'
107107
}
108108
if (!origin) {

test/unit/access-denied-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ test('acl-check accessDenied() test - default/inherited', function (t) {
107107
let containerAcl = $rdf.sym('https://alice.example.com/docs/.acl')
108108
let file1 = $rdf.sym('https://alice.example.com/docs/file1')
109109
let file2 = $rdf.sym('https://alice.example.com/docs/stuff/file2')
110+
const origin = $rdf.sym('https://apps.example.com')
111+
const malorigin = $rdf.sym('https://mallory.example.com')
112+
const trustedOrigins = null
110113
var result
111114
const store = $rdf.graph()
112115
/*
@@ -125,6 +128,24 @@ test('acl-check accessDenied() test - default/inherited', function (t) {
125128
$rdf.parse(containerAclText, store, containerAcl.uri, 'text/turtle')
126129
console.log('@@' + containerAclText + '@@@')
127130

131+
result = !aclLogic.accessDenied(store, file2, container, containerAcl, alice, [ ACL('Read')])
132+
t.ok(result, 'Alice should have read access - Public')
133+
134+
result = !aclLogic.accessDenied(store, file2, container, containerAcl, bob, [ ACL('Read')])
135+
t.ok(result, 'Bob should have read access too - Public')
136+
137+
result = !aclLogic.accessDenied(store, file2, container, containerAcl, alice, [ ACL('Read')], origin, trustedOrigins)
138+
t.ok(result, 'Alice should have read access regardless of origin - Public')
139+
140+
result = !aclLogic.accessDenied(store, file2, container, containerAcl, bob, [ ACL('Read')], origin, trustedOrigins)
141+
t.ok(result, 'Bob should have read access too regardless of origin - Public')
142+
143+
result = !aclLogic.accessDenied(store, file2, container, containerAcl, alice, [ ACL('Read')], malorigin, trustedOrigins)
144+
t.ok(result, 'Alice should have read access even with wrong origin - Public')
145+
146+
result = !aclLogic.accessDenied(store, file2, container, containerAcl, bob, [ ACL('Read')], malorigin, trustedOrigins)
147+
t.ok(result, 'Bob should have read access too even with wrong origin - Public')
148+
128149
result = aclLogic.accessDenied(store, file2, container, containerAcl, alice, [ ACL('Write')])
129150
t.ok(result, 'Alice should NOT have write acces inherited - Public')
130151

0 commit comments

Comments
 (0)