Skip to content

fix(dotenv): prevent prototype pollution during parsing #6661

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

Merged
merged 2 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotenv/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function expand(str: string, variablesMap: { [key: string]: string }): string {
* @returns The parsed object.
*/
export function parse(text: string): Record<string, string> {
const env: Record<string, string> = {};
const env: Record<string, string> = Object.create(null);

let match;
const keysForExpandCheck = [];
Expand Down
8 changes: 8 additions & 0 deletions dotenv/parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,11 @@ Deno.test("parse() expands variables", () => {
"variables within and without brackets expanded",
);
});

Deno.test("parse() result is not affected by extended Object.prototype", () => {
// deno-lint-ignore no-explicit-any
(Object.prototype as any).foo = 1;
const result = parse("bar=1");
assertEquals(result.foo, undefined);
assertEquals(result.bar, "1");
});
Loading