aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util/src/http-impl.node.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-04-24 12:42:45 -0300
committerSebastian <sebasjm@gmail.com>2023-04-24 12:42:45 -0300
commit3004ece1f8153fdf8ddb283e5d767dd5b5c2e179 (patch)
tree6666c307c2a227a77f6da7ed6a87b7709b29f6d6 /packages/taler-util/src/http-impl.node.ts
parente4bf114f60a7a76f43714183a4149406ade33d44 (diff)
downloadwallet-core-3004ece1f8153fdf8ddb283e5d767dd5b5c2e179.tar.xz
prevent http request without enable it explicitly
Diffstat (limited to 'packages/taler-util/src/http-impl.node.ts')
-rw-r--r--packages/taler-util/src/http-impl.node.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/packages/taler-util/src/http-impl.node.ts b/packages/taler-util/src/http-impl.node.ts
index 6dfce934f..4df1feaf0 100644
--- a/packages/taler-util/src/http-impl.node.ts
+++ b/packages/taler-util/src/http-impl.node.ts
@@ -49,9 +49,11 @@ const textDecoder = new TextDecoder();
export class HttpLibImpl implements HttpRequestLibrary {
private throttle = new RequestThrottler();
private throttlingEnabled = true;
+ private allowHttp = false;
constructor(args?: HttpLibArgs) {
this.throttlingEnabled = args?.enableThrottling ?? false;
+ this.allowHttp = args?.allowHttp ?? false;
}
/**
@@ -78,6 +80,16 @@ export class HttpLibImpl implements HttpRequestLibrary {
`request to origin ${parsedUrl.origin} was throttled`,
);
}
+ if (!this.allowHttp && parsedUrl.protocol !== "https:") {
+ throw TalerError.fromDetail(
+ TalerErrorCode.WALLET_NETWORK_ERROR,
+ {
+ requestMethod: method,
+ requestUrl: url,
+ },
+ `request to ${parsedUrl.origin} is not possible with protocol ${parsedUrl.protocol}`,
+ );
+ }
let timeoutMs: number | undefined;
if (typeof opt?.timeout?.d_ms === "number") {
timeoutMs = opt.timeout.d_ms;