Fix XSS weakness in airflow/www/views.py#36469
Fix XSS weakness in airflow/www/views.py#36469ZuhairORZaki wants to merge 1 commit intoapache:mainfrom ZuhairORZaki:Injection-2views.py5783650738349517611.diff
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
|
|
NIT: can you please add a unit test showing the failure scenario? |
|
Have no idea how to reproduce it. In breeze this one link redirect to the home page and just show as a text which are expected, because Flask by default use autoescape in Jinja templates |
Thank you for your feedback. So If always jinja is used to render templates and in no way situation described above can occur, then there is no attack surface. |
Seems the test failed because of using |
Yes. We require re2 globally in order to protect against other security issues (recursive denial of service for example). So you will need to switch to re2 . But my comment was to add a new unit test case not about failing static check. A unit test that passes the bad value and have the code reject it. Generally we almost never accept PR that add a functionality when there is no corresponding unit test. Because - for example it makes it impossible to verify if it still works after cherry-picking it to another branch. If we would like to merge it to 2.8 branch we need to have unit test that should fail before and work after the change - this way when we cherry-pick the change we can see that the fix works also in the bugfix branch. And yes - we do not have really a "security" issue as explained in the security report. And there is no known security attack surface, that's why we asked to just add validation as a regular PR. |
|
In addition, the is no possible to create DAG ID with this airflow/airflow/utils/helpers.py Lines 50 to 60 in e9ba37b And original regex a bit a different rather than in this PR airflow/airflow/utils/helpers.py Line 42 in e9ba37b So it also have a chance that change proposed by this PR rather than fix something just breaks someone pipeline |
|
Isn't that something that your tool should find automatically ? I think it shows the weakness of the tool. The worst thing that happens with such security reporting tools is to show false posititves. This is actually why we are very careful with those kind of tools and we blank-refuse reports showig potential problems with security - because it undermines the whole value of such tools. It creates more work for people who are volunteers and when you have to analyse those kind of issues and find false positive after false positive, you very quickly go into tool fatique and drop using it. I think the only value of such tool is that it can automatically not only detect potential value, but also automatically generate (and verify) the exploitation scenario that can be proven to work (basically this is what we expect when security issue is reported to us). So maybe @ZuhairORZaki -> treat this one as exercise. If you can make the tool works by generating such exploitation scenario, this is probably something you can report. If you cannot generate such exploitation scenario, it's probably not reportable as security bug. Ideally also if such a tool could generate not only the proposal how to fix things, a unit test that fixes it as well - that would become really useful. Other than that it mostly adds work with very limited value, and distracts from real issues, which makes the tool far too noisy to be useful |
potiuk
left a comment
There was a problem hiding this comment.
Since it does not seem to address any problem, and no scenarios to fix it can be found, I change my decision to "request changes" - and likely it should not be merged.
Will keep those in mind |


While triaging your project, our bug fixing tool generated the following message-
In file:
views.py, there is a method that is vulnerable to XSS which can compromise any cookies, session tokens and other sensitive information used with the website and browser.views.py
Here request handler method
confirmreads the value of request parameterdag_id. If no associateddagobject is found then it cobstructs a stringmsgwith it and passes it toredirect_or_jsonmethod which sends back a response containing thatmsg. Since flask automatically url decodes request parametersdag_idcan be assigned javascript code which will be sent back as part of the response.But the response content-type is application/json, so injected payload remains as a JSON data value in a JSON name/value pair and doesn't execute. So this isn't exactly an XSS vulnerability. Still if a client-side script receives this JSON value and uses some unsafe DOM update method e.g.
setInnerHTML,document.writeetc. then this could be a case of client-side XSS vulnerability.Exploitable Scenario
Consider the following simple client side page.
Let's assume the page invoked with an URL such as
The script wihtin the page reads the
dag_idparameter value from the url and sends a GET request to the above server with that value. The server then sends a Not Found response message if no associated dag object is found with thedag_idvalue included.Now an XSS attack can be carried out by sending an URL like below to a victim.
The payload here is a URL-encoded form of the following:
Since the client-side code here uses an unsafe DOM update method
(element).innerHTMLthe injected payload will execute in the victim's browser.Suggested Fix
One possible fix is sanitizing user provided data
dag_idby defining a regex pattern that represents all inappropriate characters like the following:Then any character that matches the above pattern can be replaced with an empty string using following statement:
Now if an attacker supplies javascript code as value for
dag_ide.g.<script>alert(1)</script>, it will just becomescriptalert1script.CLA Requirements:
This section is only relevant if your project requires contributors to sign a Contributor License Agreement (CLA) for external contributions.
All contributed commits are already automatically signed off.
The meaning of a signoff depends on the project, but it typically certifies that committer has the rights to submit this work under the same license and agrees to a Developer Certificate of Origin (see https://developercertificate.org/ for more information).
Sponsorship and Support:
This work is done by the security researchers from OpenRefactory and is supported by the Open Source Security Foundation (OpenSSF): Project Alpha-Omega. Alpha-Omega is a project partnering with open source software project maintainers to systematically find new, as-yet-undiscovered vulnerabilities in open source code - and get them fixed - to improve global software supply chain security.
The bug is found by running the iCR tool by OpenRefactory, Inc. and then manually triaging the results.