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

Python: Port old experimental points-to based queries #13990

Merged
merged 13 commits into from
Aug 28, 2023

Conversation

RasmusWL
Copy link
Member

I did not spend enough time on these to fully promote them, just took the minimal effort to move them off points-to so we can properly deprecate/remove that in the future 👍

@github-actions
Copy link
Contributor

QHelp previews:

python/ql/src/experimental/Security/CWE-091/XsltInjection.qhelp

XSLT query built from user-controlled sources

Processing an unvalidated XSL stylesheet can allow an attacker to change the structure and contents of the resultant XML, include arbitrary files from the file system, or execute arbitrary code.

Recommendation

This vulnerability can be prevented by not allowing untrusted user input to be passed as an XSL stylesheet. If the application logic necessitates processing untrusted XSL stylesheets, the input should be properly filtered and sanitized before use.

Example

In the example below, the XSL stylesheet is controlled by the user and hence leads to a vulnerability.

from lxml import etree
from io import StringIO
from flask import Flask, request

app = Flask(__name__)


@app.route("/xslt")
def bad():
    xsltQuery = request.args.get('xml', '')
    xslt_root = etree.XML(xsltQuery)
    f = StringIO('<foo><bar></bar></foo>')
    tree = etree.parse(f)
    result_tree = tree.xslt(xslt_root)  # Not OK

@calumgrant calumgrant requested a review from yoff August 21, 2023 11:13
Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is possible to delete python/ql/src/experimental/semmle/python/security/injection/XSLT.qll as part of this?

There is also a suggested rename, but I am not sure it is important.

It would have been nice if the first commit had been broken up so that files do not both move (get merged) and change. But in this case, through a setup with two windows, it was not too bad to compare bits of one file containing new modelling with deleted files containing old modelling...

* "template injection"
* vulnerabilities, as well as extension points for adding your own.
*/
module SqlInjection {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this module be renamed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 39e2b13

/* Sources */
import semmle.python.web.HttpRequest
/* Sinks */
import experimental.semmle.python.security.injection.XSLT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, and the entire file is deleted in the end 👍

}
}

// -----------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From here seems to be converted modelling from experimental.semmle.python.security.injection.XSLT.

Copy link
Member Author

@RasmusWL RasmusWL Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep 👍 I've removed the XSLT.qll file now 👍 (0dca8a5)

@RasmusWL RasmusWL requested a review from yoff August 28, 2023 08:43
@RasmusWL
Copy link
Member Author

It would have been nice if the first commit had been broken up so that files do not both move (get merged) and change. But in this case, through a setup with two windows, it was not too bad to compare bits of one file containing new modelling with deleted files containing old modelling...

My bad 😐

I've fixed things up, so should be good to go now 👍

yoff
yoff previously approved these changes Aug 28, 2023
Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for getting this done.

Due to change in path-graph, and including LHS of assignments
Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RasmusWL RasmusWL merged commit 38b7812 into github:main Aug 28, 2023
8 checks passed
@RasmusWL RasmusWL deleted the experimental-cleanup branch August 28, 2023 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants