@ecency/render-helper 2.2.35 → 2.2.36
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.
- package/lib/proxify-image-src.d.ts +1 -0
- package/lib/proxify-image-src.js +11 -2
- package/lib/proxify-image-src.js.map +1 -1
- package/lib/render-helper.js +1 -1
- package/package.json +1 -1
- package/src/proxify-image-src.ts +10 -1
- package/src/test/data/legacy/10.json +1 -1
- package/src/test/data/legacy/23.json +1 -1
package/package.json
CHANGED
package/src/proxify-image-src.ts
CHANGED
|
@@ -15,13 +15,22 @@ export function extractPHash(url: string): string | null {
|
|
|
15
15
|
return null
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
export function isValidUrl(url: string): boolean {
|
|
19
|
+
try {
|
|
20
|
+
return Boolean(new URL(url));
|
|
21
|
+
}
|
|
22
|
+
catch(e){
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
export function getLatestUrl(str: string): string {
|
|
19
28
|
const [last] = [...str.replace(/https?:\/\//g, '\n$&').trim().split('\n')].reverse()
|
|
20
29
|
return last
|
|
21
30
|
}
|
|
22
31
|
|
|
23
32
|
export function proxifyImageSrc(url?: string, width = 0, height = 0, format = 'match') {
|
|
24
|
-
if (!url || typeof url !== 'string') {
|
|
33
|
+
if (!url || typeof url !== 'string' || !isValidUrl(url)) {
|
|
25
34
|
return ''
|
|
26
35
|
}
|
|
27
36
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": 10,
|
|
3
3
|
"input": "Lorem ipsum dolor <img src=x onerror=alert(x)> sit amet.\n\n<a href=\"javascript:void(0)\">etiam ut sollicitudin neque</a>\n\n<a onclick=\"console.log('ss')\">Vivamus pulvinar semper porttitor</a>",
|
|
4
|
-
"result": "<p dir=\"auto\">Lorem ipsum dolor <img
|
|
4
|
+
"result": "<p dir=\"auto\">Lorem ipsum dolor <img /> sit amet.</p>\n<p dir=\"auto\"><a>etiam ut sollicitudin neque</a></p>\n<p dir=\"auto\"><a>Vivamus pulvinar semper porttitor</a></p>"
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": 23,
|
|
3
3
|
"input": "<IMG SRC=/ onerror=\"alert(String.fromCharCode(88,83,83))\"></img> <img src=x onerror=\"javascript:alert('XSS')\"> <IMG SRC=javascript:alert('XSS')> <IMG SRC=javascript:alert('XSS')> <IMG SRC=\"  javascript:alert('XSS');\">",
|
|
4
|
-
"result": "<p dir=\"auto\"><IMG SRC=/ onerror=\"alert(String.fromCharCode(88,83,83))\"> <img
|
|
4
|
+
"result": "<p dir=\"auto\"><IMG SRC=/ onerror=\"alert(String.fromCharCode(88,83,83))\"> <img /> <IMG SRC=javascript:alert('XSS')> <img /> <img /></p>"
|
|
5
5
|
}
|