Skip to content

Commit 9124f59

Browse files
authored
fix(auth): ensure schema is immutable when persisting authorization (#10588)
Refs #10569
1 parent 62b6d32 commit 9124f59

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/core/plugins/auth/wrap-actions.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @prettier
33
*/
4+
import { fromJS } from "immutable"
45

56
/**
67
* `authorize` and `logout` wrapped actions provide capacity
@@ -18,7 +19,8 @@ export const authorize = (oriAction, system) => (payload) => {
1819

1920
// create cookie
2021
try {
21-
const [{ schema, value }] = Object.values(payload)
22+
const [{ schema: payloadSchema, value }] = Object.values(payload)
23+
const schema = fromJS(payloadSchema)
2224
const isApiKeyAuth = schema.get("type") === "apiKey"
2325
const isInCookie = schema.get("in") === "cookie"
2426
const isApiKeyInCookie = isApiKeyAuth && isInCookie

test/unit/core/plugins/auth/wrap-actions.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ describe("Cookie based apiKey persistence in document.cookie", () => {
4242
)
4343
})
4444

45+
it("should persist cookie in document.cookie if schema is a plain object", () => {
46+
const system = {
47+
getConfigs: () => ({
48+
persistAuthorization: true,
49+
}),
50+
}
51+
const payload = {
52+
api_key: {
53+
schema: {
54+
type: "apiKey",
55+
name: "apiKeyCookie",
56+
in: "cookie",
57+
},
58+
value: "test",
59+
},
60+
}
61+
62+
authorize(jest.fn(), system)(payload)
63+
64+
expect(document.cookie).toEqual(
65+
"apiKeyCookie=test; SameSite=None; Secure"
66+
)
67+
})
68+
4569
it("should delete cookie from document.cookie", () => {
4670
const payload = fromJS({
4771
api_key: {

0 commit comments

Comments
 (0)