@@ -7,6 +7,16 @@ import { fallbackIpfsGateway, ipfsGateway } from 'src/ui-config/governanceConfig
77type MemorizeMetadata = Record < string , ProposalMetadata > ;
88const MEMORIZE : MemorizeMetadata = { } ;
99
10+ const SAFE_MATTER_OPTIONS = {
11+ engines : {
12+ javascript : {
13+ parse : ( ) => {
14+ throw new Error ( 'JavaScript front matter is not supported' ) ;
15+ } ,
16+ } ,
17+ } ,
18+ } ;
19+
1020/**
1121 * Composes a URI based off of a given IPFS CID hash and gateway
1222 * @param {string } hash - The IPFS CID hash
@@ -58,15 +68,15 @@ export async function parseRawIpfs(rawIpfsContent: string, hash: string) {
5868 if ( MEMORIZE [ ipfsHash ] ) return MEMORIZE [ ipfsHash ] ;
5969 try {
6070 const response : ProposalMetadata = await JSON . parse ( rawIpfsContent ) ;
61- const { content, data } = matter ( response . description ) ;
71+ const { content, data } = matter ( response . description , SAFE_MATTER_OPTIONS ) ;
6272 MEMORIZE [ ipfsHash ] = {
6373 ...response ,
6474 ipfsHash,
6575 description : content ,
6676 ...data ,
6777 } ;
6878 } catch ( e ) {
69- const { content, data } = matter ( rawIpfsContent ) ;
79+ const { content, data } = matter ( rawIpfsContent , SAFE_MATTER_OPTIONS ) ;
7080 MEMORIZE [ ipfsHash ] = {
7181 ...( data as ProposalMetadata ) ,
7282 ipfsHash,
@@ -99,7 +109,7 @@ async function fetchFromIpfs(hash: string, gateway: string): Promise<ProposalMet
99109 // Store in cache
100110 try {
101111 const response : ProposalMetadata = await ipfsResponse . json ( ) ;
102- const { content, data } = matter ( response . description ) ;
112+ const { content, data } = matter ( response . description , SAFE_MATTER_OPTIONS ) ;
103113 MEMORIZE [ ipfsHash ] = {
104114 ...response ,
105115 ipfsHash,
@@ -108,7 +118,7 @@ async function fetchFromIpfs(hash: string, gateway: string): Promise<ProposalMet
108118 } ;
109119 } catch ( e ) {
110120 const text = await clone . text ( ) ;
111- const { content, data } = matter ( text ) ;
121+ const { content, data } = matter ( text , SAFE_MATTER_OPTIONS ) ;
112122 MEMORIZE [ ipfsHash ] = {
113123 ...( data as ProposalMetadata ) ,
114124 ipfsHash,
0 commit comments