- Notifications
You must be signed in to change notification settings - Fork 305
Block cookie auth from non-subdomains, but allow all other auth from everywhere#835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -169,6 +169,27 @@ function initWebId (argv, app, ldp){ | ||
| const useSecureCookies = !!argv.sslKey // use secure cookies when over HTTPS | ||
| const sessionHandler = session(sessionSettings(useSecureCookies, argv.host)) | ||
| app.use(sessionHandler) | ||
| // Reject cookies from third-party applications. | ||
| // Otherwise, when a user is logged in to their Solid server, | ||
| // any third-party application could perform authenticated requests | ||
| // without permission by including the credentials set by the Solid server. | ||
| app.use((req, res, next) =>{ | ||
| const origin = req.headers.origin | ||
| const userId = req.session.userId | ||
| // Exception: allow logout requests from all third-party apps | ||
| // such that OIDC client can log out via cookie auth | ||
| // TODO: remove this exception when OIDC clients | ||
| // use Bearer token to authenticate instead of cookie | ||
| // (https://github.com/solid/node-solid-server/pull/835#issuecomment-426429003) | ||
| if (!argv.host.allowsSessionFor(userId, origin) && !isLogoutRequest(req)){ | ||
| debug(`Rejecting session for ${userId} from ${origin}`) | ||
| // Destroy session data | ||
| delete req.session.userId | ||
| // Ensure this modified session is not saved | ||
| req.session.save = (done) => done() | ||
| } | ||
| next() | ||
| }) | ||
| let accountManager = AccountManager.from({ | ||
| authMethod: argv.auth, | ||
| @@ -187,30 +208,20 @@ function initWebId (argv, app, ldp){ | ||
| // Set up authentication-related API endpoints and app.locals | ||
| initAuthentication(app, argv) | ||
| // Protect against requests from third-party applications | ||
| app.use((req, res, next) =>{ | ||
| // Reject cookies from third-party applications. | ||
| // Otherwise, when a user is logged in to their Solid server, | ||
| // any third-party application could perform authenticated requests | ||
| // without permission by including the credentials set by the Solid server. | ||
| const origin = req.headers.origin | ||
| const userId = req.session.userId | ||
| if (!argv.host.allowsSessionFor(userId, origin)){ | ||
| debug(`Rejecting session for ${userId} from ${origin}`) | ||
| // Destroy session data | ||
| delete req.session.userId | ||
| // Ensure this modified session is not saved | ||
| req.session.save = done => done() | ||
| } | ||
| next() | ||
| }) | ||
| // Set up per-host LDP middleware | ||
| if (argv.multiuser){ | ||
| app.use(vhost('*', LdpMiddleware(corsSettings))) | ||
| } | ||
| } | ||
| /** | ||
| * Determines whether the given request is a logout request | ||
| */ | ||
| function isLogoutRequest (req){ | ||
| // TODO: this is a hack that hard-codes OIDC paths, | ||
| // this code should live in the OIDC module | ||
| return req.path === '/logout' || req.path === '/goodbye' | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm.. | ||
| } | ||
| /** | ||
| * Sets up authentication-related routes and handlers for the app. | ||
| * | ||
Uh oh!
There was an error while loading. Please reload this page.