Skip to content

Commit d256943

Browse files
Merge pull request #793 from solid/fix/allow-external-logout
Do not block third-party cookies from reaching auth handlers
2 parents c1cf810 + 4d0c094 commit d256943

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

lib/create-app.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,7 @@ function initWebId (argv, app, ldp) {
167167
// (for same-domain browsing by people only)
168168
const useSecureCookies = !!argv.sslKey // use secure cookies when over HTTPS
169169
const sessionHandler = session(sessionSettings(useSecureCookies, argv.host))
170-
app.use((req, res, next) => {
171-
sessionHandler(req, res, () => {
172-
// Reject cookies from third-party applications.
173-
// Otherwise, when a user is logged in to their Solid server,
174-
// any third-party application could perform authenticated requests
175-
// without permission by including the credentials set by the Solid server.
176-
const origin = req.headers.origin
177-
const userId = req.session.userId
178-
if (!argv.host.allowsSessionFor(userId, origin)) {
179-
debug(`Rejecting session for ${userId} from ${origin}`)
180-
// Destroy session data
181-
delete req.session.userId
182-
// Ensure this modified session is not saved
183-
req.session.save = (done) => done()
184-
}
185-
next()
186-
})
187-
})
170+
app.use(sessionHandler)
188171

189172
let accountManager = AccountManager.from({
190173
authMethod: argv.auth,
@@ -203,6 +186,25 @@ function initWebId (argv, app, ldp) {
203186
// Set up authentication-related API endpoints and app.locals
204187
initAuthentication(app, argv)
205188

189+
// Protect against requests from third-party applications
190+
app.use((req, res, next) => {
191+
// Reject cookies from third-party applications.
192+
// Otherwise, when a user is logged in to their Solid server,
193+
// any third-party application could perform authenticated requests
194+
// without permission by including the credentials set by the Solid server.
195+
const origin = req.headers.origin
196+
const userId = req.session.userId
197+
if (!argv.host.allowsSessionFor(userId, origin)) {
198+
debug(`Rejecting session for ${userId} from ${origin}`)
199+
// Destroy session data
200+
delete req.session.userId
201+
// Ensure this modified session is not saved
202+
req.session.save = done => done()
203+
}
204+
next()
205+
})
206+
207+
// Set up per-host LDP middleware
206208
if (argv.multiuser) {
207209
app.use(vhost('*', LdpMiddleware(corsSettings)))
208210
}

0 commit comments

Comments
 (0)