forked from opensearch-project/security
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split up a value into multiple cookie payloads (opensearch-project#1352)
* PoC for splitting up a value into multiple cookie payloads Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com> * Cookie splitting for OpenId and SAML Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com> * Changes after review comments Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com> * WIP: First unit tests Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com> * More unit tests Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com> * Fix for multi auth, request argument was missing Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com> * Fixed linting errors Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com> * Added one additional cookie for the SAML integration tests Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com> --------- Signed-off-by: Jochen Kressin <jochen.kressin-gh@eliatra.com> Co-authored-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com>
- Loading branch information
1 parent
ce57d86
commit c5cdbbb
Showing
15 changed files
with
927 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import { httpServerMock } from '../../../../../../src/core/server/http/http_server.mocks'; | ||
|
||
import { OpenSearchDashboardsRequest } from '../../../../../../src/core/server/http/router'; | ||
|
||
import { OpenIdAuthentication } from './openid_auth'; | ||
import { SecurityPluginConfigType } from '../../../index'; | ||
import { SecuritySessionCookie } from '../../../session/security_cookie'; | ||
import { deflateValue } from '../../../utils/compression'; | ||
import { | ||
IRouter, | ||
CoreSetup, | ||
ILegacyClusterClient, | ||
Logger, | ||
SessionStorageFactory, | ||
} from '../../../../../../src/core/server'; | ||
|
||
describe('test OpenId authHeaderValue', () => { | ||
let router: IRouter; | ||
let core: CoreSetup; | ||
let esClient: ILegacyClusterClient; | ||
let sessionStorageFactory: SessionStorageFactory<SecuritySessionCookie>; | ||
let logger: Logger; | ||
|
||
// Consistent with auth_handler_factory.test.ts | ||
beforeEach(() => {}); | ||
|
||
const config = ({ | ||
openid: { | ||
header: 'authorization', | ||
scope: [], | ||
extra_storage: { | ||
cookie_prefix: 'testcookie', | ||
additional_cookies: 5, | ||
}, | ||
}, | ||
} as unknown) as SecurityPluginConfigType; | ||
|
||
test('make sure that cookies with authHeaderValue are still valid', async () => { | ||
const openIdAuthentication = new OpenIdAuthentication( | ||
config, | ||
sessionStorageFactory, | ||
router, | ||
esClient, | ||
core, | ||
logger | ||
); | ||
|
||
const mockRequest = httpServerMock.createRawRequest(); | ||
const osRequest = OpenSearchDashboardsRequest.from(mockRequest); | ||
|
||
const cookie: SecuritySessionCookie = { | ||
credentials: { | ||
authHeaderValue: 'Bearer eyToken', | ||
}, | ||
}; | ||
|
||
const expectedHeaders = { | ||
authorization: 'Bearer eyToken', | ||
}; | ||
|
||
const headers = openIdAuthentication.buildAuthHeaderFromCookie(cookie, osRequest); | ||
|
||
expect(headers).toEqual(expectedHeaders); | ||
}); | ||
|
||
test('get authHeaderValue from split cookies', async () => { | ||
const openIdAuthentication = new OpenIdAuthentication( | ||
config, | ||
sessionStorageFactory, | ||
router, | ||
esClient, | ||
core, | ||
logger | ||
); | ||
|
||
const testString = 'Bearer eyCombinedToken'; | ||
const testStringBuffer: Buffer = deflateValue(testString); | ||
const cookieValue = testStringBuffer.toString('base64'); | ||
const cookiePrefix = config.openid!.extra_storage.cookie_prefix; | ||
const splitValueAt = Math.ceil( | ||
cookieValue.length / config.openid!.extra_storage.additional_cookies | ||
); | ||
const mockRequest = httpServerMock.createRawRequest({ | ||
state: { | ||
[cookiePrefix + '1']: cookieValue.substring(0, splitValueAt), | ||
[cookiePrefix + '2']: cookieValue.substring(splitValueAt), | ||
}, | ||
}); | ||
const osRequest = OpenSearchDashboardsRequest.from(mockRequest); | ||
|
||
const cookie: SecuritySessionCookie = { | ||
credentials: { | ||
authHeaderValueExtra: true, | ||
}, | ||
}; | ||
|
||
const expectedHeaders = { | ||
authorization: testString, | ||
}; | ||
|
||
const headers = openIdAuthentication.buildAuthHeaderFromCookie(cookie, osRequest); | ||
|
||
expect(headers).toEqual(expectedHeaders); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.