ensure single content is json to prevent DOS on indexer

This commit is contained in:
Barry Gitarts 2019-12-04 12:24:39 -05:00
parent a34cb16d78
commit d19e25b334
4 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1,2 @@
export let skipBlocks: number[] = [6891630]

View File

@ -0,0 +1,7 @@
import { Bytes } from "@graphprotocol/graph-ts"
export function isJson(manifest: Bytes): boolean {
let manifestString = manifest.toHexString()
let first = manifestString.slice(0, 4)
return first == '0x7b'
}

View File

@ -15,6 +15,8 @@ import {
DonateCall,
} from "../generated/Contract/Contract"
import { Profile, PledgesInfo, Pledge, ProjectInfo } from "../generated/schema"
import { skipBlocks } from "./helpers/ignore"
import { isJson } from "./helpers/json"
export function handleAddGiver(call: AddGiverCall): void {
@ -66,12 +68,11 @@ export function handleUpdateProject(call: UpdateProjectCall): void {
function createProjectInfo(content: String, profile: Profile, isFile: boolean = false): void {
let hash = content.split('/').slice(-1)[0]
let contentHash = isFile ? hash : hash + '/manifest.json'
let manifest = ipfs.cat(contentHash)
let manifest: Bytes | null = ipfs.cat(contentHash)
if (manifest == null) {
log.info('manifest is null', [])
if (!isFile) createProjectInfo(content, profile, true)
} else {
} else if (isJson(manifest as Bytes)) {
let parsed = json.fromBytes(manifest as Bytes).toObject()
log.info(
'ipfs title: {}',