Skip to content

Commit

Permalink
Use null prototype for map values (#622)
Browse files Browse the repository at this point in the history
* Use null prototype for map values

This fixes alerts for prototype pollution vunerabillities. In my assessment the risk here is near-zero, as the keys are trusted configured values and hashes. However, this is still better practice.

* fix formatting, lerna config
  • Loading branch information
mike-marcacci authored Jan 5, 2024
1 parent f51979f commit d57f322
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"packages": ["packages/*"],
"useWorkspaces": true,
"version": "3.1.0-alpha.52",
"npmClient": "npm"
}
23 changes: 12 additions & 11 deletions packages/http-proxy-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export default class AuthXClientProxy extends EventEmitter {
[refreshToken: string]: {
[hash: string]: string;
};
} = {};
} = Object.create(null);

/**
* A request fetches fresh access tokens from AuthX.
Expand All @@ -208,7 +208,7 @@ export default class AuthXClientProxy extends EventEmitter {
timeout: ReturnType<typeof setTimeout>;
};
};
} = {};
} = Object.create(null);

/**
* A refresh timeout is responsible for initiating a request to AuthX that
Expand All @@ -218,7 +218,7 @@ export default class AuthXClientProxy extends EventEmitter {
[refreshToken: string]: {
[hash: string]: ReturnType<typeof setTimeout>;
};
} = {};
} = Object.create(null);

/**
* An eviction timeout is responsible for preventing tokens from being
Expand All @@ -230,7 +230,7 @@ export default class AuthXClientProxy extends EventEmitter {
[refreshToken: string]: {
[hash: string]: ReturnType<typeof setTimeout>;
};
} = {};
} = Object.create(null);

/**
* An expiration timeout is responsible for removing expired tokens from the
Expand All @@ -241,7 +241,7 @@ export default class AuthXClientProxy extends EventEmitter {
[refreshToken: string]: {
[hash: string]: ReturnType<typeof setTimeout>;
};
} = {};
} = Object.create(null);

public readonly server: Server;

Expand Down Expand Up @@ -458,7 +458,7 @@ export default class AuthXClientProxy extends EventEmitter {

// Create a new eviction timeout.
this._evictionTimeouts[refreshToken] =
this._evictionTimeouts[refreshToken] || {};
this._evictionTimeouts[refreshToken] || Object.create(null);
this._evictionTimeouts[refreshToken][hash] = setTimeout(
() => this._evict(refreshToken, hash),
(this._config.evictDormantCachedTokensThreshold || 600) * 1000
Expand Down Expand Up @@ -584,7 +584,7 @@ export default class AuthXClientProxy extends EventEmitter {

// Set an expiration timeout.
this._expirationTimeouts[refreshToken] =
this._expirationTimeouts[refreshToken] || {};
this._expirationTimeouts[refreshToken] || Object.create(null);
if (this._expirationTimeouts[refreshToken][hash]) {
clearTimeout(this._expirationTimeouts[refreshToken][hash]);
}
Expand All @@ -599,7 +599,7 @@ export default class AuthXClientProxy extends EventEmitter {

// Set a refresh timeout.
this._refreshTimeouts[refreshToken] =
this._refreshTimeouts[refreshToken] || {};
this._refreshTimeouts[refreshToken] || Object.create(null);
if (this._refreshTimeouts[refreshToken][hash]) {
clearTimeout(this._refreshTimeouts[refreshToken][hash]);
}
Expand All @@ -611,7 +611,7 @@ export default class AuthXClientProxy extends EventEmitter {

// Cache the access token.
this._accessTokens[refreshToken] =
this._accessTokens[refreshToken] || {};
this._accessTokens[refreshToken] || Object.create(null);
this._accessTokens[refreshToken][hash] = accessToken;

return accessToken;
Expand All @@ -632,7 +632,7 @@ export default class AuthXClientProxy extends EventEmitter {
// using incorrect credentials), and don't retry those.
if (retry) {
this._refreshTimeouts[refreshToken] =
this._refreshTimeouts[refreshToken] || {};
this._refreshTimeouts[refreshToken] || Object.create(null);
if (this._refreshTimeouts[refreshToken][hash]) {
clearTimeout(this._refreshTimeouts[refreshToken][hash]);
}
Expand Down Expand Up @@ -664,7 +664,8 @@ export default class AuthXClientProxy extends EventEmitter {
};

// Store the request.
this._requests[refreshToken] = this._requests[refreshToken] || {};
this._requests[refreshToken] =
this._requests[refreshToken] || Object.create(null);
this._requests[refreshToken][hash] = request;
return request.promise;
}
Expand Down

0 comments on commit d57f322

Please sign in to comment.