@ape.swap/bonds-sdk 7.0.4 → 7.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,23 +1,53 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
+
const TAG_WHITELIST = ['a', 'br', 'span']; // Allowed tags
|
|
4
|
+
const ATTR_WHITELIST = ['target', 'rel', 'style', 'href']; // Allowed attributes
|
|
5
|
+
const URL_PROTOCOL_WHITELIST = ['http:', 'https:', 'mailto:']; // Allowed href schemes
|
|
6
|
+
const STYLE_PROPERTY_WHITELIST = ['color']; // Allowed inline style properties
|
|
7
|
+
// Returns true only for URLs with an allowed scheme. The URL parser strips the whitespace and control
|
|
8
|
+
// characters browsers ignore, so obfuscated values like "java\tscript:" are caught too
|
|
9
|
+
function isSafeURL(value) {
|
|
10
|
+
try {
|
|
11
|
+
return URL_PROTOCOL_WHITELIST.includes(new URL(value, window.location.href).protocol);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// Keeps only whitelisted style properties, so content can't overlay or restyle the host page
|
|
18
|
+
function sanitizeStyle(el) {
|
|
19
|
+
const { style } = el;
|
|
20
|
+
for (const property of Array.from(style)) {
|
|
21
|
+
if (!STYLE_PROPERTY_WHITELIST.includes(property))
|
|
22
|
+
style.removeProperty(property);
|
|
23
|
+
}
|
|
24
|
+
if (!style.length)
|
|
25
|
+
el.removeAttribute('style');
|
|
26
|
+
}
|
|
3
27
|
// Custom HTML sanitizer
|
|
4
28
|
function sanitizeHTML(html) {
|
|
5
|
-
|
|
6
|
-
|
|
29
|
+
if (typeof window === 'undefined' || typeof DOMParser === 'undefined')
|
|
30
|
+
return '';
|
|
7
31
|
const doc = new DOMParser().parseFromString(html, 'text/html');
|
|
8
32
|
const elements = doc.body.querySelectorAll('*');
|
|
9
33
|
for (const el of elements) {
|
|
10
34
|
// Remove elements that are not in the whitelist
|
|
11
|
-
if (!
|
|
35
|
+
if (!TAG_WHITELIST.includes(el.tagName.toLowerCase())) {
|
|
12
36
|
el?.parentNode?.removeChild(el);
|
|
13
37
|
continue;
|
|
14
38
|
}
|
|
15
39
|
// Loop through the element's attributes and remove those that are not in the whitelist
|
|
16
40
|
Array.from(el.attributes).forEach((attr) => {
|
|
17
|
-
|
|
41
|
+
const name = attr.name.toLowerCase();
|
|
42
|
+
if (!ATTR_WHITELIST.includes(name) || (name === 'href' && !isSafeURL(attr.value))) {
|
|
18
43
|
el.removeAttribute(attr.name);
|
|
19
44
|
}
|
|
20
45
|
});
|
|
46
|
+
if (el.hasAttribute('style'))
|
|
47
|
+
sanitizeStyle(el);
|
|
48
|
+
// Links opening a new tab must not get a handle on the host page (reverse tabnabbing)
|
|
49
|
+
if (el.hasAttribute('target'))
|
|
50
|
+
el.setAttribute('rel', 'noopener noreferrer');
|
|
21
51
|
}
|
|
22
52
|
return doc.body.innerHTML;
|
|
23
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/SafeHTMLComponent/index.tsx"],"sourcesContent":["import * as React from 'react'\n\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/SafeHTMLComponent/index.tsx"],"sourcesContent":["import * as React from 'react'\n\nconst TAG_WHITELIST = ['a', 'br', 'span'] // Allowed tags\nconst ATTR_WHITELIST = ['target', 'rel', 'style', 'href'] // Allowed attributes\nconst URL_PROTOCOL_WHITELIST = ['http:', 'https:', 'mailto:'] // Allowed href schemes\nconst STYLE_PROPERTY_WHITELIST = ['color'] // Allowed inline style properties\n\n// Returns true only for URLs with an allowed scheme. The URL parser strips the whitespace and control\n// characters browsers ignore, so obfuscated values like \"java\\tscript:\" are caught too\nfunction isSafeURL(value: string) {\n try {\n return URL_PROTOCOL_WHITELIST.includes(new URL(value, window.location.href).protocol)\n } catch {\n return false\n }\n}\n\n// Keeps only whitelisted style properties, so content can't overlay or restyle the host page\nfunction sanitizeStyle(el: HTMLElement) {\n const { style } = el\n for (const property of Array.from(style)) {\n if (!STYLE_PROPERTY_WHITELIST.includes(property)) style.removeProperty(property)\n }\n if (!style.length) el.removeAttribute('style')\n}\n\n// Custom HTML sanitizer\nfunction sanitizeHTML(html: string) {\n if (typeof window === 'undefined' || typeof DOMParser === 'undefined') return ''\n\n const doc = new DOMParser().parseFromString(html, 'text/html')\n const elements = doc.body.querySelectorAll('*')\n\n for (const el of elements) {\n // Remove elements that are not in the whitelist\n if (!TAG_WHITELIST.includes(el.tagName.toLowerCase())) {\n el?.parentNode?.removeChild(el)\n continue\n }\n\n // Loop through the element's attributes and remove those that are not in the whitelist\n Array.from(el.attributes).forEach((attr) => {\n const name = attr.name.toLowerCase()\n if (!ATTR_WHITELIST.includes(name) || (name === 'href' && !isSafeURL(attr.value))) {\n el.removeAttribute(attr.name)\n }\n })\n\n if (el.hasAttribute('style')) sanitizeStyle(el as HTMLElement)\n\n // Links opening a new tab must not get a handle on the host page (reverse tabnabbing)\n if (el.hasAttribute('target')) el.setAttribute('rel', 'noopener noreferrer')\n }\n\n return doc.body.innerHTML\n}\n\nconst SafeHTMLComponent = ({ html }: { html: string }) => {\n const sanitizedHTML = sanitizeHTML(html)\n\n return <div dangerouslySetInnerHTML={{ __html: sanitizedHTML }} />\n}\n\nexport default SafeHTMLComponent\n"],"names":["_jsx"],"mappings":";;AAEA,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;AACzC,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AACzD,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA;AAC7D,MAAM,wBAAwB,GAAG,CAAC,OAAO,CAAC,CAAA;AAE1C;AACA;AACA,SAAS,SAAS,CAAC,KAAa,EAAA;AAC9B,I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CAAC,WAAW,EAAE;YACpC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE;AACjF,gBAAA,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;YAC/B;AACF,QAAA,CAAC,CAAC;AAEF,QAAA,IAAI,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC;YAAE,aAAa,CAAC,EAAiB,CAAC;;AAG9D,QAAA,IAAI,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC;AAAE,YAAA,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,qBAAqB,CAAC;IAC9E;AAEA,IAAA,OAAO,GAAG,CAAC,IAAI,CAAC,SAAS;AAC3B;AAEA,MAAM,iBAAiB,GAAG,CAAC,EAAE,IAAI,EAAoB,KAAI;AACvD,IAAA,MAAM,aAAa,GAAG,YAAY,CAAC,IAAI,CAAC;IAExC,OAAOA,GAAA,CAAA,KAAA,EAAA,EAAK,uBAAuB,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,EAAA,CAAI;AACpE;;;;"}
|
|
@@ -18,7 +18,7 @@ const LinkShare = ({ userBill }) => {
|
|
|
18
18
|
const mainUrl = useURLByEnvironment('mainUrl');
|
|
19
19
|
const apiUrl = useURLByEnvironment('apiV2') ?? '';
|
|
20
20
|
const bondAddress = userBill?.bond?.chainId === ChainId.SOL ? bondNFTData?.contractAddress : bondNFTData?.data?.billNftAddress;
|
|
21
|
-
const shareUrl = `${mainUrl}/bond-nft?bondAddress=${bondAddress}%26bondChain=${bondNFTData?.chainId}%26tokenId=${userBill?.id}
|
|
21
|
+
const shareUrl = `${mainUrl}/bond-nft?bondAddress=${bondAddress}%26bondChain=${bondNFTData?.chainId}%26tokenId=${userBill?.id}`;
|
|
22
22
|
const text = `I've filled my bags with $${userBill?.bond?.earnToken.symbol} at a discount, thanks to Bonds-only on @apebond! Check it out: `;
|
|
23
23
|
const handleShare = async (url, social) => {
|
|
24
24
|
if (isLoading[0] || isLoading[1]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkShare.js","sources":["../../../../../src/views/YourBondsModal/components/LinkShare/LinkShare.tsx"],"sourcesContent":["import { useState } from 'react'\nimport Spinner from '../../../../components/uikit-sdk/Spinner'\nimport Flex from '../../../../components/uikit-sdk/Flex'\nimport { useURLByEnvironment } from '../../../../state/useSDKConfig'\nimport { UserBill, UserBillNftData } from '../../../../types/yourbonds'\nimport { generateImageFromTemplate } from './utils'\nimport track from '../../../../utils/track'\nimport { ChainId } from '@ape.swap/apeswap-lists'\nimport Twitter from '../../../../components/uikit-sdk/Svg/Icons/Twitter'\n\nconst LinkShare = ({ userBill }: { userBill: UserBill | undefined }) => {\n // State\n const [isLoading, setIsLoading] = useState<boolean[]>([false, false])\n\n // Static data\n const bondNFTData: UserBillNftData | undefined = userBill?.nftData\n const chainId = userBill?.bond?.chainId\n // Hooks\n const mainUrl = useURLByEnvironment('mainUrl')\n const apiUrl = useURLByEnvironment('apiV2') ?? ''\n const bondAddress =\n userBill?.bond?.chainId === ChainId.SOL ? bondNFTData?.contractAddress : bondNFTData?.data?.billNftAddress\n const shareUrl = `${mainUrl}/bond-nft?bondAddress=${bondAddress}%26bondChain=${bondNFTData?.chainId}%26tokenId=${userBill?.id}
|
|
1
|
+
{"version":3,"file":"LinkShare.js","sources":["../../../../../src/views/YourBondsModal/components/LinkShare/LinkShare.tsx"],"sourcesContent":["import { useState } from 'react'\nimport Spinner from '../../../../components/uikit-sdk/Spinner'\nimport Flex from '../../../../components/uikit-sdk/Flex'\nimport { useURLByEnvironment } from '../../../../state/useSDKConfig'\nimport { UserBill, UserBillNftData } from '../../../../types/yourbonds'\nimport { generateImageFromTemplate } from './utils'\nimport track from '../../../../utils/track'\nimport { ChainId } from '@ape.swap/apeswap-lists'\nimport Twitter from '../../../../components/uikit-sdk/Svg/Icons/Twitter'\n\nconst LinkShare = ({ userBill }: { userBill: UserBill | undefined }) => {\n // State\n const [isLoading, setIsLoading] = useState<boolean[]>([false, false])\n\n // Static data\n const bondNFTData: UserBillNftData | undefined = userBill?.nftData\n const chainId = userBill?.bond?.chainId\n // Hooks\n const mainUrl = useURLByEnvironment('mainUrl')\n const apiUrl = useURLByEnvironment('apiV2') ?? ''\n const bondAddress =\n userBill?.bond?.chainId === ChainId.SOL ? bondNFTData?.contractAddress : bondNFTData?.data?.billNftAddress\n const shareUrl = `${mainUrl}/bond-nft?bondAddress=${bondAddress}%26bondChain=${bondNFTData?.chainId}%26tokenId=${userBill?.id}`\n const text = `I've filled my bags with $${userBill?.bond?.earnToken.symbol} at a discount, thanks to Bonds-only on @apebond! Check it out: `\n const handleShare = async (url: string, social: string) => {\n if (isLoading[0] || isLoading[1]) {\n console.log('something is off')\n return\n }\n track({\n event: 'referral',\n chain: chainId,\n data: {\n cat: `${social.toUpperCase()} Share Bond`,\n bond: bondNFTData?.data?.payoutTokenData.symbol,\n },\n })\n setIsLoading(social === 'x' ? [true, false] : [false, true])\n await generateImageFromTemplate(bondNFTData, url, apiUrl)\n setIsLoading([false, false])\n }\n\n return (\n <Flex\n className=\"ape:bg-white3 ape:lg:bg-white4 ape:rounded-normal ape:justify-center ape:items-center ape:p-[2px_10px_2px_5px] ape:font-semibold ape:text-[12px] ape:h-[22px] ape:cursor-pointer ape:hover:bg-white5\"\n onClick={() => handleShare(`https://twitter.com/intent/tweet?text=${text}&url=${shareUrl}`, 'x')}\n >\n <Flex>{isLoading[0] ? <Spinner size={16} /> : <Twitter width={20} />}</Flex>\n <Flex>SHARE</Flex>\n </Flex>\n )\n}\n\nexport default LinkShare\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;AAUA,MAAM,SAAS,GAAG,CAAC,EAAE,QAAQ,EAAsC,KAAI;;AAErE,IAAA,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAY,CAAC,KAAK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G,EAAE,MAAM,CAAC;AACzD,QAAA,YAAY,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC9B,IAAA,CAAC;IAED,QACEA,IAAA,CAAC,IAAI,EAAA,EACH,SAAS,EAAC,sMAAsM,EAChN,OAAO,EAAE,MAAM,WAAW,CAAC,CAAA,sCAAA,EAAyC,IAAI,CAAA,KAAA,EAAQ,QAAQ,CAAA,CAAE,EAAE,GAAG,CAAC,EAAA,QAAA,EAAA,CAEhGC,GAAA,CAAC,IAAI,EAAA,EAAA,QAAA,EAAE,SAAS,CAAC,CAAC,CAAC,GAAGA,GAAA,CAAC,OAAO,EAAA,EAAC,IAAI,EAAE,EAAE,EAAA,CAAI,GAAGA,GAAA,CAAC,OAAO,EAAA,EAAC,KAAK,EAAE,EAAE,EAAA,CAAI,EAAA,CAAQ,EAC5EA,GAAA,CAAC,IAAI,EAAA,EAAA,QAAA,EAAA,OAAA,EAAA,CAAa,CAAA,EAAA,CACb;AAEX;;;;"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Ape Bond SDK",
|
|
4
4
|
"author": "Ape Bond",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "7.0.
|
|
6
|
+
"version": "7.0.6",
|
|
7
7
|
"module": "dist/main.js",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"types": "dist/main.d.ts",
|
|
@@ -193,7 +193,7 @@
|
|
|
193
193
|
"clsx": "2.1.1",
|
|
194
194
|
"framer-motion": "11.18.2",
|
|
195
195
|
"lightweight-charts": "4.2.3",
|
|
196
|
-
"lodash-es": "4.
|
|
196
|
+
"lodash-es": "4.18.1"
|
|
197
197
|
},
|
|
198
198
|
"devDependencies": {
|
|
199
199
|
"@aptos-labs/ts-sdk": "6.3.1",
|
|
@@ -219,7 +219,6 @@
|
|
|
219
219
|
"@tailwindcss/vite": "^4.3.3",
|
|
220
220
|
"@tanstack/react-query": "5.90.2",
|
|
221
221
|
"@tanstack/react-query-devtools": "5.90.2",
|
|
222
|
-
"@types/lodash": "4.17.24",
|
|
223
222
|
"@types/lodash-es": "4.17.12",
|
|
224
223
|
"@types/node": "24.12.0",
|
|
225
224
|
"@types/react": "18.3.28",
|
|
@@ -229,7 +228,7 @@
|
|
|
229
228
|
"eslint-plugin-react": "7.37.5",
|
|
230
229
|
"eslint-plugin-react-hooks": "5.2.0",
|
|
231
230
|
"husky": "9.1.7",
|
|
232
|
-
"knip": "
|
|
231
|
+
"knip": "6.48.0",
|
|
233
232
|
"lint-staged": "16.4.0",
|
|
234
233
|
"prettier": "3.8.1",
|
|
235
234
|
"react": "19.2.8",
|
|
@@ -240,7 +239,7 @@
|
|
|
240
239
|
"typescript": "6.0.3",
|
|
241
240
|
"typescript-eslint": "^8.68.0",
|
|
242
241
|
"viem": "2.55.2",
|
|
243
|
-
"vite": "7.3.
|
|
242
|
+
"vite": "7.3.8",
|
|
244
243
|
"wagmi": "2.19.5"
|
|
245
244
|
},
|
|
246
245
|
"browserslist": {
|