Skip to content

Commit

Permalink
fix: Use encodeURIComponent to prevent XSS
Browse files Browse the repository at this point in the history
- Updated the game mode and room ID parameters to use `encodeURIComponent` before including them in URLs.
- This change ensures that special characters are properly encoded, preventing potential XSS attacks.
- Applied this update to the room creation and joining logic in `home.ejs` and `play-now.ejs`.

This fix enhances the security of the application by preventing cross-site scripting (XSS) vulnerabilities.
  • Loading branch information
TKanX committed Nov 12, 2024
1 parent e1390db commit 0ed2b6c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions views/pages/home.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,21 @@
// Handle Join Room
document.getElementById("join-room").addEventListener("click", () => {
const roomId = encodeURIComponent(document.getElementById("room-id").value);
window.location.href = `/game?type=join&roomId=${roomId}`;
const roomId = document.getElementById("room-id").value;
window.location.href = `/game?type=join&roomId=${encodeURIComponent(roomId)}`;
});
// Create Room event listeners
document.getElementById("create-room-single").addEventListener("click", () => {
const playerCount = document.getElementById("player-count-single").value;
const gameMode = `classic-${playerCount}-single`;
window.location.href = `/game?type=create&gameMode=${gameMode}`;
window.location.href = `/game?type=create&gameMode=${encodeURIComponent(gameMode)}`;
});
document.getElementById("create-room-multi").addEventListener("click", () => {
const playerCount = document.getElementById("player-count-multi").value;
const gameMode = `classic-${playerCount}`;
window.location.href = `/game?type=create&gameMode=${gameMode}`;
window.location.href = `/game?type=create&gameMode=${encodeURIComponent(gameMode)}`;
});
// Initialize GameNetwork (Socket.IO)
Expand Down
4 changes: 2 additions & 2 deletions views/pages/play-now.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@
document.getElementById("start-game-single").addEventListener("click", () => {
const playerCount = document.getElementById("player-count-single").value;
const gameMode = `classic-${playerCount}-single`;
window.location.href = `/game?type=queue&gameMode=${gameMode}`;
window.location.href = `/game?type=queue&gameMode=${encodeURIComponent(gameMode)}`;
});
document.getElementById("start-game-multi").addEventListener("click", () => {
const playerCount = document.getElementById("player-count-multi").value;
const gameMode = `classic-${playerCount}`;
window.location.href = `/game?type=queue&gameMode=${gameMode}`;
window.location.href = `/game?type=queue&gameMode=${encodeURIComponent(gameMode)}`;
});
</script>
</body>
Expand Down

0 comments on commit 0ed2b6c

Please sign in to comment.