Skip to content

Commit b06eacc

Browse files
authored
Merge pull request #1177 from solid/fix/#1176
Users with invalid tokens can now access public resources
2 parents 065ad18 + 2bfe697 commit b06eacc

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

lib/api/authn/webid-oidc.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,17 @@ function initialize (app, argv) {
3131
app.use('/', middleware(oidc))
3232

3333
// Perform the actual authentication
34-
app.use('/', oidc.rs.authenticate())
34+
app.use('/', async (req, res, next) => {
35+
oidc.rs.authenticate()(req, res, (err) => {
36+
// Error handling should be deferred to the ldp in case a user with a bad token is trying
37+
// to access a public resource
38+
if (err) {
39+
req.authError = err
40+
res.status(200)
41+
}
42+
next()
43+
})
44+
})
3545

3646
// Expose session.userId
3747
app.use('/', (req, res, next) => {

lib/handlers/allow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function allow (mode, checkPermissionsForDirectory) {
6666
}
6767
}
6868
}
69-
const error = await req.acl.getError(userId, mode)
69+
const error = req.authError || await req.acl.getError(userId, mode)
7070
debug(`${mode} access denied to ${userId || '(none)'}: ${error.status} - ${error.message}`)
7171
next(error)
7272
}

test/integration/errors-oidc-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ describe('OIDC error handling', function () {
9494
.expect('WWW-Authenticate', 'Bearer realm="https://localhost:3457", scope="openid webid", error="invalid_token", error_description="Access token is expired"')
9595
.expect(401)
9696
})
97+
98+
it('should return a 200 if the resource is public', () => {
99+
return server.get('/public/')
100+
.set('Authorization', 'Bearer ' + expiredToken)
101+
.expect(200)
102+
})
97103
})
98104
})
99105
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# ACL resource for the public folder
2+
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
3+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
4+
5+
# The owner has all permissions
6+
<#owner>
7+
a acl:Authorization;
8+
acl:agent <https://localhost:3457/profile/card#me>;
9+
acl:accessTo <./>;
10+
acl:default <./>;
11+
acl:mode acl:Read, acl:Write, acl:Control.
12+
13+
# The public has read permissions
14+
<#public>
15+
a acl:Authorization;
16+
acl:agentClass foaf:Agent;
17+
acl:accessTo <./>;
18+
acl:default <./>;
19+
acl:mode acl:Read.

0 commit comments

Comments
 (0)