-
Notifications
You must be signed in to change notification settings - Fork 155
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
Support cancel rendering requests on client cancellation #588
Conversation
} catch (err) { | ||
this.log.error('Error while trying to prepare page for screenshot', 'url', options.url, 'err', err.stack); | ||
} | ||
await page.goto(options.url, { waitUntil: 'networkidle0', timeout: options.timeout * 1000, signal }); |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
URL
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 22 days ago
To fix the problem, we need to ensure that the user input is validated and sanitized before being used in the page.goto
method. One effective way to do this is to use an allow-list of acceptable URLs or domains. This way, we can ensure that only trusted URLs are used in the request.
- Create an allow-list of acceptable URLs or domains.
- Validate the user input against this allow-list.
- If the input is valid, proceed with the request; otherwise, reject the request with an appropriate error message.
-
Copy modified line R182 -
Copy modified lines R186-R188
@@ -181,2 +181,3 @@ | ||
|
||
const allowedUrls = ['https://example.com', 'https://another-example.com']; | ||
if (!req.query.url) { | ||
@@ -184,2 +185,5 @@ | ||
} | ||
if (!allowedUrls.includes(req.query.url)) { | ||
throw boom.badRequest('Invalid url parameter'); | ||
} | ||
|
|
||
await page.goto(options.url, { waitUntil: 'networkidle0', timeout: options.timeout * 1000 }); | ||
await page.goto(options.url, { waitUntil: 'networkidle0', timeout: options.timeout * 1000, signal }); |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
URL
user-provided value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Tested and works as expected 🚀
Currently when client cancels the requests, the rendering request continues to run until it ends.
This PR fixes that by stopping the rendering process.
It has two main benefits:
Failed to get render key from cache
. This is displayed when the image renderer tries to access Grafana after the request is cancelled because the render key has been deleted but this makes it more complicated to investigate real issues.Fixes #186