Improve security: check token for console access.

This commit is contained in:
Julien Fontanet 2015-11-17 14:51:26 +01:00
parent f6911ca195
commit de62464ad8
2 changed files with 13 additions and 1 deletions

View File

@ -40,6 +40,7 @@
"bluebird": "^2.9.14",
"body-parser": "^1.13.3",
"connect-flash": "^0.1.1",
"cookie": "^0.2.3",
"cookie-parser": "^1.3.5",
"cron": "^1.0.9",
"d3-time-format": "^0.1.3",

View File

@ -45,7 +45,8 @@ import connectFlash from 'connect-flash'
import cookieParser from 'cookie-parser'
import expressSession from 'express-session'
import passport from 'passport'
import {Strategy as LocalStrategy} from 'passport-local'
import { parse as parseCookies } from 'cookie'
import { Strategy as LocalStrategy } from 'passport-local'
// ===================================================================
@ -489,6 +490,16 @@ const setUpConsoleProxy = (webServer, xo) => {
const [, id] = matches
try {
// TODO: factorize permissions checking in an Express middleware.
{
const { token } = parseCookies(req.headers.cookie)
const user = await xo.authenticateUser({ token })
if (!await xo.hasPermissions(user.id, [ [ id, 'operate' ] ])) { // eslint-disable-line space-before-keywords
throw new InvalidCredential()
}
}
const xapi = xo.getXAPI(id, ['VM', 'VM-controller'])
const vmConsole = xapi.getVmConsole(id)