diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-01-06 11:50:46 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-01-06 11:50:46 +0900 |
| commit | 94582453820655d11cb6dff8ad62148742591103 (patch) | |
| tree | 8f5daf00c67e0a536afce99c6dd248a65e741706 /src/api | |
| parent | Refactor: Extract isNativeToken method (diff) | |
| download | sharkey-94582453820655d11cb6dff8ad62148742591103.tar.gz sharkey-94582453820655d11cb6dff8ad62148742591103.tar.bz2 sharkey-94582453820655d11cb6dff8ad62148742591103.zip | |
[BREAKING CHANGE] Improve security
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/authenticate.ts | 2 | ||||
| -rw-r--r-- | src/api/endpoints/auth/accept.js | 15 | ||||
| -rw-r--r-- | src/api/streaming.ts | 2 |
3 files changed, 16 insertions, 3 deletions
diff --git a/src/api/authenticate.ts b/src/api/authenticate.ts index 832517379f..0a888e72d3 100644 --- a/src/api/authenticate.ts +++ b/src/api/authenticate.ts @@ -43,7 +43,7 @@ export default (req: express.Request) => new Promise<IAuthContext>(async (resolv }); } else { const userkeyDoc = await Userkey.findOne({ - key: token + hash: token }); if (userkeyDoc === null) { diff --git a/src/api/endpoints/auth/accept.js b/src/api/endpoints/auth/accept.js index 7c45650c6b..9eb5d2e7e2 100644 --- a/src/api/endpoints/auth/accept.js +++ b/src/api/endpoints/auth/accept.js @@ -4,6 +4,8 @@ * Module dependencies */ import rndstr from 'rndstr'; +const crypto = require('crypto'); +import App from '../../models/app'; import AuthSess from '../../models/auth-session'; import Userkey from '../../models/userkey'; @@ -41,12 +43,23 @@ module.exports = (params, user) => }); if (exist === null) { + // Lookup app + const app = await App.findOne({ + app_id: session.app_id + }); + + // Generate Hash + const sha512 = crypto.createHash('sha512'); + sha512.update(key + app.secret); + const hash = sha512.digest('hex'); + // Insert userkey doc await Userkey.insert({ created_at: new Date(), app_id: session.app_id, user_id: user._id, - key: key + key: key, + hash: hash }); } diff --git a/src/api/streaming.ts b/src/api/streaming.ts index 84a0f9ddf4..dd28a0bc1e 100644 --- a/src/api/streaming.ts +++ b/src/api/streaming.ts @@ -64,7 +64,7 @@ function authenticate(connection: websocket.connection, token: string): Promise< resolve(user); } else { const userkey = await Userkey.findOne({ - key: token + hash: token }); if (userkey == null) { |