@@ -168,7 +168,24 @@ function initWebId (argv, app, ldp) {
168
168
// (for same-domain browsing by people only)
169
169
const useSecureCookies = ! ! argv . sslKey // use secure cookies when over HTTPS
170
170
const sessionHandler = session ( sessionSettings ( useSecureCookies , argv . host ) )
171
- app . use ( sessionHandler )
171
+ app . use ( ( req , res , next ) => {
172
+ sessionHandler ( req , res , ( ) => {
173
+ // Reject cookies from third-party applications.
174
+ // Otherwise, when a user is logged in to their Solid server,
175
+ // any third-party application could perform authenticated requests
176
+ // without permission by including the credentials set by the Solid server.
177
+ const origin = req . headers . origin
178
+ const userId = req . session . userId
179
+ if ( ! argv . host . allowsSessionFor ( userId , origin ) ) {
180
+ debug ( `Rejecting session for ${ userId } from ${ origin } ` )
181
+ // Destroy session data
182
+ delete req . session . userId
183
+ // Ensure this modified session is not saved
184
+ req . session . save = ( done ) => done ( )
185
+ }
186
+ next ( )
187
+ } )
188
+ } )
172
189
173
190
let accountManager = AccountManager . from ( {
174
191
authMethod : argv . auth ,
@@ -187,25 +204,6 @@ function initWebId (argv, app, ldp) {
187
204
// Set up authentication-related API endpoints and app.locals
188
205
initAuthentication ( app , argv )
189
206
190
- // Protect against requests from third-party applications
191
- app . use ( ( req , res , next ) => {
192
- // Reject cookies from third-party applications.
193
- // Otherwise, when a user is logged in to their Solid server,
194
- // any third-party application could perform authenticated requests
195
- // without permission by including the credentials set by the Solid server.
196
- const origin = req . headers . origin
197
- const userId = req . session . userId
198
- if ( ! argv . host . allowsSessionFor ( userId , origin ) ) {
199
- debug ( `Rejecting session for ${ userId } from ${ origin } ` )
200
- // Destroy session data
201
- delete req . session . userId
202
- // Ensure this modified session is not saved
203
- req . session . save = done => done ( )
204
- }
205
- next ( )
206
- } )
207
-
208
- // Set up per-host LDP middleware
209
207
if ( argv . multiuser ) {
210
208
app . use ( vhost ( '*' , LdpMiddleware ( corsSettings ) ) )
211
209
}
0 commit comments