|
| 1 | + |
| 2 | +<template> |
| 3 | + <button @click="openSecurePopup" class="btn-primary"> |
| 4 | + 🔒 Open Secure Popup |
| 5 | + </button> |
| 6 | + |
| 7 | + <div v-if="popupMessage" class="message-box"> |
| 8 | + {{ popupMessage }} |
| 9 | + </div> |
| 10 | + |
| 11 | + <canvas |
| 12 | + ref="securityCanvas" |
| 13 | + width="300" |
| 14 | + height="200" |
| 15 | + @click="demonstrateClickjacking" |
| 16 | + class="border border-gray-300 cursor-pointer" |
| 17 | + ></canvas> |
| 18 | + |
| 19 | + <button @click="playSecurityDemo" class="play-btn"> |
| 20 | + ▶️ Play Security Demo |
| 21 | + </button> |
| 22 | +</template> |
| 23 | + |
| 24 | +<script setup> |
| 25 | +import { ref } from "vue"; |
| 26 | +
|
| 27 | +const popupMessage = ref(""); |
| 28 | +const securityCanvas = ref(null); |
| 29 | +
|
| 30 | +const openSecurePopup = () => { |
| 31 | + const popup = window.open("", "_blank", "width=400,height=300"); |
| 32 | + popup.document.write(` |
| 33 | + <html><body> |
| 34 | + <h3>Secure Popup</h3> |
| 35 | + <p>This popup demonstrates secure communication.</p> |
| 36 | + <button onclick="parent.postMessage('Hello from popup', '*')">Send Message</button> |
| 37 | + </body></html> |
| 38 | + `); |
| 39 | +}; |
| 40 | +
|
| 41 | +const demonstrateClickjacking = () => { |
| 42 | + const canvas = securityCanvas.value; |
| 43 | + const ctx = canvas.getContext("2d"); |
| 44 | +
|
| 45 | + // Draw clickjacking visualization |
| 46 | + ctx.fillStyle = "red"; |
| 47 | + ctx.fillRect(0, 0, canvas.width, canvas.height); |
| 48 | + ctx.fillStyle = "white"; |
| 49 | + ctx.font = "16px Arial"; |
| 50 | + ctx.fillText("Clickjacking Protection Active", 10, 100); |
| 51 | +}; |
| 52 | +
|
| 53 | +const playSecurityDemo = () => { |
| 54 | + const canvas = securityCanvas.value; |
| 55 | + const ctx = canvas.getContext("2d"); |
| 56 | +
|
| 57 | + // Animate security demonstration |
| 58 | + let frame = 0; |
| 59 | + const animate = () => { |
| 60 | + ctx.clearRect(0, 0, canvas.width, canvas.height); |
| 61 | +
|
| 62 | + // Draw frame border |
| 63 | + ctx.strokeStyle = frame % 60 < 30 ? "green" : "red"; |
| 64 | + ctx.lineWidth = 3; |
| 65 | + ctx.strokeRect(5, 5, canvas.width - 10, canvas.height - 10); |
| 66 | +
|
| 67 | + ctx.fillStyle = "black"; |
| 68 | + ctx.font = "14px Arial"; |
| 69 | + ctx.fillText( |
| 70 | + `Frame Security: ${frame % 60 < 30 ? "SAFE" : "BLOCKED"}`, |
| 71 | + 10, |
| 72 | + 30 |
| 73 | + ); |
| 74 | +
|
| 75 | + frame++; |
| 76 | + if (frame < 120) requestAnimationFrame(animate); |
| 77 | + }; |
| 78 | +
|
| 79 | + animate(); |
| 80 | +}; |
| 81 | +
|
| 82 | +// Listen for popup messages |
| 83 | +window.addEventListener("message", (event) => { |
| 84 | + popupMessage.value = event.data; |
| 85 | +}); |
| 86 | +</script> |
0 commit comments