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

xss #163

Open
pawvan opened this issue Jul 29, 2024 · 0 comments
Open

xss #163

pawvan opened this issue Jul 29, 2024 · 0 comments

Comments

@pawvan
Copy link

pawvan commented Jul 29, 2024

The injectScript function contains potential security risks and error handling issues:

XSS Vulnerability:

Issue: The use of eval within the injectScript function can execute arbitrary JavaScript code, leading to a potential XSS (Cross-Site Scripting) vulnerability. Despite sanitization attempts (e.g., replacing </script>), eval remains a security risk.
Details: Dynamic execution of JavaScript via eval can allow for malicious inputs to be executed, posing a significant security threat.
Error Handling:

Issue: The try-catch block is used to handle errors, but the error message in the catch block is not sufficiently informative. Additionally, console.log is used, which may not be visible or effective for all testing scenarios.
Details: Enhancing error handling to provide more informative feedback and improve visibility would be beneficial.
Proposed Solution
Improve Security:

Solution: Avoid using eval for executing dynamic scripts. Consider safer alternatives, such as using predefined functions or secure libraries for executing dynamic logic.
Enhance Error Handling:

Solution: Improve error handling by providing more detailed error messages and using appropriate logging or notification mechanisms. Consider using console.error for better visibility of errors.
Code Snippet
Here is the current implementation:

typescript
Copy code
export async function injectScript(page: Page, script: string):Promise {
let safeScript = script.replace(/</script>/g, '<\/script>');
return await page.setContent(`

<script> async function main() { try{ const amount = eval(${JSON.stringify(safeScript)}); document.querySelector('div').textContent = amount; } catch(error){ console.log('Script error:', error); document.querySelector('div').textContent = "error executing script"; } } main(); </script>
`); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant