fix(jinja): ensure consistent escaping in url_param helper#39066
fix(jinja): ensure consistent escaping in url_param helper#39066l3tchupkt wants to merge 5 commits intoapache:masterfrom
Conversation
fix sqli in url param
Code Review Agent Run #b807a0Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
@l3tchupkt thanks for opening out, can you help adding a unit test? Edit: also, can you link to an existing issue? |
|
@hainenber Thanks for the feedback! I’ll add a unit test to cover the behavior of Regarding the issue reference , this change addresses a reported issue currently being tracked by the security team, so I’ll avoid linking a public issue for now. Please let me know if you'd prefer a placeholder reference or any specific test coverage. |
|
@hainenber Hi, I’ve added additional test coverage to validate the fix more thoroughly. The new tests focus on edge cases around I also included a specific test to confirm that query parameters overriding All tests are passing locally, and the changes do not impact existing functionality. Please let me know if you’d like me to extend coverage further or adjust anything. |
|
@hainenber could you please check this ?? |
|
I'm cross-checking this issue with other maintainers. Re: your fix, it's logically sound but lets wait for the cross-check result. |
|
@hainenber okey thanks for the update : ) |
There was a problem hiding this comment.
Pull request overview
This PR fixes inconsistent escaping behavior in the Jinja url_param() helper by ensuring values pulled from the URL query string go through the same escaping flow as values coming from form_data["url_params"] (while preserving query-string precedence).
Changes:
- Consolidate
url_param()value resolution so query-string values no longer bypassescape_result. - Apply escaping uniformly for both query-string and
form_data["url_params"]sources whenescape_result=Trueand a dialect is available. - Add unit tests covering escaped/unescaped query-string behavior, falsy/empty query values, and query precedence over
form_data.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
superset/jinja_context.py |
Unifies url_param() value resolution and ensures consistent escaping for query-string and form-data sourced params. |
tests/unit_tests/jinja_context_test.py |
Adds targeted unit tests for query-string escaping, precedence, and edge cases (empty and falsy values). |
|
@dpgaspar Hi, could you please review this when you have a moment? |
SUMMARY
Ensure consistent handling of parameters in the url_param() helper by applying escaping logic uniformly regardless of input source.
Previously, values obtained from request arguments and form data were processed through different code paths, leading to inconsistent behavior. This change consolidates the logic so that all inputs follow the same processing and escaping flow when enabled, while preserving the existing precedence of request arguments over form data.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable.
TESTING INSTRUCTIONS
Enable template processing in configuration:
FEATURE_FLAGS = {
"ENABLE_TEMPLATE_PROCESSING": True,
}
Create or use a dataset with a query like:
SELECT * FROM logs WHERE source = '{{ url_param("source") }}'
Send a request with a parameter via query string:
/api/v1/chart/data?source=test_value
Verify that the parameter is processed correctly and queries execute as expected.
Repeat the same using form_data["url_params"] and confirm consistent behavior.
Test edge cases:
Ensure no regressions in existing functionality using url_param().
ADDITIONAL INFORMATION
Author: Lakshmikanthan K (letchupkt)
LinkedIn: linkedin.com/in/lakshmikanthank