Skip to content
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

add config to restrict maximum content length #120

Draft
wants to merge 1 commit into
base: mdt/preconfig-providers
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const ETH_REGISTRY_ABI = [
// response timeout: 1 min
const RESPONSE_TIMEOUT = 60 * 1000;

// avatar cannot be greater than 50mb
const MAX_CONTENT_LENGTH = 50000000;

export {
ADDRESS_ETH_REGISTRAR,
ADDRESS_ETH_REGISTRY,
Expand All @@ -39,6 +42,7 @@ export {
INAMEWRAPPER,
IPFS_GATEWAY,
INFURA_API_KEY,
MAX_CONTENT_LENGTH,
RESPONSE_TIMEOUT,
SERVER_URL,
};
4 changes: 2 additions & 2 deletions src/service/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
RetrieveURIFailed,
TextRecordNotFound,
} from '../base';
import { IPFS_GATEWAY } from '../config';
import { IPFS_GATEWAY, MAX_CONTENT_LENGTH } from '../config';

const window = new JSDOM('').window;

Expand Down Expand Up @@ -75,7 +75,7 @@ export class AvatarMetadata {
}

if (avatarURI?.startsWith('http')) {
const response = await fetch(avatarURI);
const response = await fetch(avatarURI, { size: MAX_CONTENT_LENGTH });

assert(response, 'Response is empty');

Expand Down