Skip to content

Commit

Permalink
chore: Internal request filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
tommoor committed Jul 5, 2022
1 parent 4e189b8 commit c6fdffb
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
2 changes: 0 additions & 2 deletions .eslintrc
Expand Up @@ -12,7 +12,6 @@
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:react-hooks/recommended",
"plugin:prettier/recommended"
],
"plugins": [
Expand All @@ -21,7 +20,6 @@
"eslint-plugin-import",
"eslint-plugin-node",
"eslint-plugin-react",
"eslint-plugin-react-hooks",
"import"
],
"rules": {
Expand Down
6 changes: 5 additions & 1 deletion app/.eslintrc
@@ -1,6 +1,10 @@
{
"extends": [
"../.eslintrc"
"../.eslintrc",
"plugin:react-hooks/recommended",
],
"plugins": [
"eslint-plugin-react-hooks",
],
"env": {
"jest": true,
Expand Down
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -133,6 +133,7 @@
"mobx-react": "^6.3.1",
"natural-sort": "^1.0.0",
"nodemailer": "^6.6.1",
"node-fetch": "2.6.7",
"outline-icons": "^1.43.1",
"oy-vey": "^0.10.0",
"passport": "^0.4.1",
Expand Down Expand Up @@ -182,6 +183,7 @@
"reflect-metadata": "^0.1.13",
"refractor": "^3.5.0",
"regenerator-runtime": "^0.13.7",
"request-filtering-agent": "^1.1.2",
"semver": "^7.3.2",
"sequelize": "^6.20.1",
"sequelize-cli": "^6.4.1",
Expand Down Expand Up @@ -247,6 +249,7 @@
"@types/mime-types": "^2.1.1",
"@types/natural-sort": "^0.0.21",
"@types/node": "15.12.2",
"@types/node-fetch": "^2.6.2",
"@types/nodemailer": "^6.4.4",
"@types/passport-oauth2": "^1.4.11",
"@types/prosemirror-commands": "^1.0.1",
Expand Down
3 changes: 3 additions & 0 deletions server/queues/tasks/DeliverWebhookTask.ts
@@ -1,4 +1,5 @@
import fetch from "fetch-with-proxy";
import { useAgent } from "request-filtering-agent";
import { Op } from "sequelize";
import WebhookDisabledEmail from "@server/emails/templates/WebhookDisabledEmail";
import env from "@server/env";
Expand Down Expand Up @@ -535,6 +536,8 @@ export default class DeliverWebhookTask extends BaseTask<Props> {
method: "POST",
headers: requestHeaders,
body: JSON.stringify(requestBody),
redirect: "error",
agent: useAgent(subscription.url),
});
status = response.ok ? "success" : "failed";
} catch (err) {
Expand Down
4 changes: 3 additions & 1 deletion server/typings/fetch-with-proxy.d.ts
@@ -1,3 +1,5 @@
declare module "fetch-with-proxy" {
export = fetch;
import nodeFetch from "node-fetch";

export = nodeFetch;
}
1 change: 0 additions & 1 deletion server/utils/passport.ts
Expand Up @@ -82,7 +82,6 @@ export class StateStore {
export async function request(endpoint: string, accessToken: string) {
const response = await fetch(endpoint, {
method: "GET",
credentials: "same-origin",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
Expand Down
6 changes: 4 additions & 2 deletions server/utils/s3.ts
Expand Up @@ -3,6 +3,7 @@ import util from "util";
import AWS from "aws-sdk";
import { addHours, format } from "date-fns";
import fetch from "fetch-with-proxy";
import { useAgent } from "request-filtering-agent";
import { v4 as uuidv4 } from "uuid";
import env from "@server/env";
import Logger from "@server/logging/Logger";
Expand Down Expand Up @@ -185,8 +186,9 @@ export const uploadToS3FromUrl = async (
}

try {
const res = await fetch(url);
// @ts-expect-error buffer exists, need updated typings
const res = await fetch(url, {
agent: useAgent(url),
});
const buffer = await res.buffer();
await s3
.putObject({
Expand Down
20 changes: 20 additions & 0 deletions yarn.lock
Expand Up @@ -2809,6 +2809,14 @@
resolved "https://registry.yarnpkg.com/@types/natural-sort/-/natural-sort-0.0.21.tgz#5583cfcd250f72e45af8611ef515d4e881f49556"
integrity sha512-WYMWhAQLuBym+6qQ2Ojptm6qIACnkkYYs08sj+PVgRCrB6b7k1QpTRk0yMmxhlpPn5MbXcSfd6sHOYlzaokU3w==

"@types/node-fetch@^2.6.2":
version "2.6.2"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.2.tgz#d1a9c5fd049d9415dce61571557104dec3ec81da"
integrity sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==
dependencies:
"@types/node" "*"
form-data "^3.0.0"

"@types/node@*", "@types/node@>=12", "@types/node@>=13.7.0":
version "17.0.38"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.38.tgz#f8bb07c371ccb1903f3752872c89f44006132947"
Expand Down Expand Up @@ -8610,6 +8618,11 @@ ioredis@^4.27.0, ioredis@^4.28.0:
redis-parser "^3.0.0"
standard-as-callback "^2.1.0"

ipaddr.js@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-2.0.1.tgz#eca256a7a877e917aeb368b0a7497ddf42ef81c0"
integrity sha512-1qTgH9NG+IIJ4yfKs2e6Pp1bZg8wbDbKHT21HrLIeYBTRLgMYKnMTPAuI3Lcs61nfx5h1xlXnbJtH1kX5/d/ng==

is-absolute@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-absolute/-/is-absolute-1.0.0.tgz#395e1ae84b11f26ad1795e73c17378e48a301576"
Expand Down Expand Up @@ -12924,6 +12937,13 @@ replace-ext@^1.0.0:
resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-1.0.1.tgz#2d6d996d04a15855d967443631dd5f77825b016a"
integrity sha512-yD5BHCe7quCgBph4rMQ+0KkIRKwWCrHDOX1p1Gp6HwjPM5kVoCdKGNhN7ydqqsX6lJEnQDKZ/tFMiEdQ1dvPEw==

request-filtering-agent@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/request-filtering-agent/-/request-filtering-agent-1.1.2.tgz#327deaff55dfee0b32efa0025ff9b8e6e121f2f4"
integrity sha512-v6uYIoey6rhe+nQXB5rlYEWJI+5SrnvM72XGeLUsykzu2omOEPoW4QmzEH+8/sheK4M/hwQ85L7aPj1cTJfPLg==
dependencies:
ipaddr.js "^2.0.0"

require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
Expand Down

0 comments on commit c6fdffb

Please sign in to comment.