Skip to content

Commit 0cfbca5

Browse files
authored
Limit the amount of / stripped to avoid potential regex DoS (cosmos#1675)
1 parent 31db121 commit 0cfbca5

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/faucet-client/src/faucetclient.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import fetch from "cross-fetch";
22

3+
/**
4+
* Strip trailing `/`s
5+
*/
6+
function stripTrailingSlash(baseUrl: string): string {
7+
// Limit the amount of / stripped to avoid potential regex DoS
8+
return baseUrl.replace(/(\/{0,20})$/, "");
9+
}
10+
311
export class FaucetClient {
412
private readonly baseUrl: string;
513

614
public constructor(baseUrl: string) {
715
if (!baseUrl.match(/^https?:\/\//)) {
816
throw new Error("Expected base url to start with http:// or https://");
917
}
10-
11-
// Strip trailing /
12-
const strippedBaseUrl = baseUrl.replace(/(\/+)$/, "");
13-
this.baseUrl = strippedBaseUrl;
18+
this.baseUrl = stripTrailingSlash(baseUrl);
1419
}
1520

1621
public async credit(address: string, denom: string): Promise<void> {

0 commit comments

Comments
 (0)