-
Notifications
You must be signed in to change notification settings - Fork 10
Fix the object clone issue, close #49 #55
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { Host, PacScript, SimpleProxyServer } from "@/adapters"; | ||
| import { deepClone } from "./utils"; | ||
|
|
||
| export type ProxyAuthInfo = { | ||
| username: string; | ||
|
|
@@ -103,7 +104,9 @@ export function onProfileUpdate(callback: (p: ProfilesStorage) => void) { | |
| } | ||
|
|
||
| async function overwriteProfiles(profiles: ProfilesStorage) { | ||
| await Host.set(keyProfileStorage, profiles); | ||
| // Deep clone to remove any Proxy objects before saving | ||
| const clonedProfiles = deepClone(profiles); | ||
| await Host.set(keyProfileStorage, clonedProfiles); | ||
| onProfileUpdateListeners.map((cb) => cb(profiles)); | ||
| } | ||
|
|
||
|
|
@@ -115,14 +118,16 @@ async function overwriteProfiles(profiles: ProfilesStorage) { | |
| */ | ||
| export async function saveProfile(profile: ProxyProfile) { | ||
| const data = await listProfiles(); | ||
| data[profile.profileID] = profile; | ||
| // Deep clone the profile to remove any Proxy objects before saving | ||
| data[profile.profileID] = deepClone(profile); | ||
| await overwriteProfiles(data); | ||
| } | ||
|
|
||
| export async function saveManyProfiles(profiles: ProxyProfile[]) { | ||
| let data = await listProfiles(); | ||
| profiles.forEach((p) => { | ||
| data[p.profileID] = p; | ||
| // Deep clone each profile to remove any Proxy objects before saving | ||
| data[p.profileID] = deepClone(p); | ||
|
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. Similar to the if (p.profileID !== '__proto__') {
data[p.profileID] = deepClone(p);
} |
||
| }); | ||
| await overwriteProfiles(data); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /** | ||
| * Deep clone an object to remove all Proxy objects (e.g., from Vue reactivity). | ||
| * This is necessary because chrome.storage and browser.storage use structured clone | ||
| * which cannot clone Proxy objects. | ||
| */ | ||
| export function deepClone<T>(obj: T): T { | ||
| return JSON.parse(JSON.stringify(obj)); | ||
| } | ||
|
Comment on lines
+6
to
+8
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. Using |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is vulnerable to Prototype Pollution due to the use of user-controlled
profile.profileIDas a key indata. An attacker could use"__proto__"to inject properties intoObject.prototype, which is then persistently saved. Furthermore, thedeepClonecall here is redundant, as theoverwriteProfilesfunction, which is called subsequently, already performs a deep clone on the entireprofilesobject before saving.