Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Escape single quote when generating HTML popup #539

Open
1 task done
Gustry opened this issue Dec 11, 2023 · 3 comments
Open
1 task done

[Bug]: Escape single quote when generating HTML popup #539

Gustry opened this issue Dec 11, 2023 · 3 comments
Assignees
Labels

Comments

@Gustry
Copy link
Member

Gustry commented Dec 11, 2023

What is the bug?

if the field has a apostrophe in the field name, the generated HTML maptip will have an error

Versions

Lizmap plugin latest

Check Lizmap plugin

  • I have done the step just before in the Lizmap QGIS desktop plugin before opening this ticket. Otherwise, my ticket is not considered valid and might get closed.
@Gustry Gustry added the Bug label Dec 11, 2023
@Gustry Gustry self-assigned this Dec 11, 2023
@sudhanshu112233shukla
Copy link

Hi, I'd like to work on this issue. It looks like single quotes in popup content are not properly escaped, which could break the HTML structure or introduce security vulnerabilities like XSS.

A possible fix could be using htmlspecialchars() in PHP or JavaScript escaping techniques before rendering the popup content.

Would you like a specific approach (PHP or JS) for escaping? Also, are there any cases where escaping should be skipped (e.g., when using Markdown)?

Let me know your thoughts!!

@sudhanshu112233shukla
Copy link

$popupContent = "O'Reilly's Bookstore";
$escapedContent = htmlspecialchars($popupContent, ENT_QUOTES, 'UTF-8');
echo "

$escapedContent
";

( Using htmlspecialchars() we can fix PHP)

function escapeSingleQuote(str) {
return str.replace(/'/g, "'"); // Replace single quotes with HTML entity
}
let popupContent = "O'Reilly's Bookstore";
let safeContent = escapeSingleQuote(popupContent);
document.getElementById("popup").innerHTML = safeContent;

( JavaScript Fix Using .replace() )

@sudhanshu112233shukla
Copy link

can we use this fix ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants