|
1 | 1 | window.renderContent = async (content) => { |
2 | 2 | const short = await (async () => { |
3 | 3 | const whitelist = [ |
4 | | - "about", "youtube", "contact", "blog", "cv", |
| 4 | + "about", "youtube", "contact", "blog", "cv", "challenges", |
5 | 5 | "flag{congrats_you_found_a_meaningless_flag_from_a_meaningless_repository_in_github}" |
6 | 6 | ] |
7 | 7 | if (whitelist.includes(content)) { |
8 | 8 | return await (await fetch(`../contents/${content}.html`)).text(); |
9 | 9 | } else { |
10 | | - if ([".", "/", "{", "}", "]", "[", ")", "("].filter(str => content.includes(str)).length > 0) { |
| 10 | + if ([".", "/", "{", "}", "]", "[", ")", "("].filter(str => content?.includes(str)).length > 0) { |
11 | 11 | return "<span style=\"width: 100%;\"><center>Hacker, please dont attack me :(</center></span>" |
12 | 12 | } else { |
13 | 13 | const { origin } = new URL(document.location.href); |
@@ -53,6 +53,37 @@ window.renderContent = async (content) => { |
53 | 53 | characterData: true |
54 | 54 | }); |
55 | 55 |
|
| 56 | + const parser = new DOMParser(); |
| 57 | + const doc = parser.parseFromString(short, 'text/html'); |
| 58 | + const scripts = doc.querySelectorAll("script"); |
| 59 | + |
| 60 | + const newShort = doc; |
| 61 | + newShort.querySelectorAll("script").forEach((script) => script.remove()); |
| 62 | + |
56 | 63 | // Render the content |
57 | | - contentPreTag.innerHTML = "\n" + short; |
| 64 | + contentPreTag.innerHTML = `\n${newShort.body.innerHTML.trim()}`; |
| 65 | + |
| 66 | + // Execute script tags inside the content |
| 67 | + scripts.forEach((script) => { |
| 68 | + const newScript = document.createElement("script"); |
| 69 | + |
| 70 | + // Copy all attributes |
| 71 | + for (const attr of script.attributes) { |
| 72 | + newScript.setAttribute(attr.name, attr.value); |
| 73 | + } |
| 74 | + |
| 75 | + if (script.src) { |
| 76 | + // For external scripts |
| 77 | + newScript.src = script.src; |
| 78 | + } else { |
| 79 | + // For inline scripts |
| 80 | + newScript.text = script.textContent; |
| 81 | + } |
| 82 | + |
| 83 | + // Append to trigger execution |
| 84 | + document.body.appendChild(newScript); |
| 85 | + |
| 86 | + // Clean up |
| 87 | + newScript.remove(); |
| 88 | + }); |
58 | 89 | } |
0 commit comments