microsoft / microsoft/typespec

[http-client-python][bug]: use of xml.etree.ElementTree causing CWE-611 report

Open
#8,083 9 comments 0 reactions 0 assignees View on GitHub
bug emitter:client:python
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

### Describe the bug

As a user I want to use typespec generated clients that are free from CWE warnings.

# Actual behavior
Client is getting CWE warnings due to insecure function use.

The clients are using `xml.etree.ElementTree.fromstring` which is considered insecure generating CWE-611 warnings.

The jinja templates literally are trying to ignore this problem by using `# nosec` tags.
* https://github.com/microsoft/typespec/blob/f7fc86f9f8e04bd719757e9f4436358d322b097f/packages/http-client-python/generator/pygen/codegen/templates/serialization.py.jinja2#L103
* https://github.com/microsoft/typespec/blob/f7fc86f9f8e04bd719757e9f4436358d322b097f/packages/http-client-python/generator/pygen/codegen/templates/serialization.py.jinja2#L103

# Expected behavior
Clients would use defusedxml which is considered safe.

It would be best to use the safe package. At a minimum a statement regarding why this may be ignored would be helpful.

### Reproduction

npm install -g @typespec/compiler
tsp --version
1.2.1
tsp init
... choose REST
... include python client emitter
// update tsp config.yaml to emit to `emitter-output-dir: "{cwd}/clientpy"`
tsp compile .
snyk code test

[FireShot Capture 018 - PR Check - Snyk - \[app.snyk.io\].pdf](https://github.com/user-attachments/files/21552833/FireShot.Capture.018.-.PR.Check.-.Snyk.-.app.snyk.io.pdf)

Details:

- Review README on branch: https://github.com/joekiller/typespec-pyclient-snyk-CWE-611/tree/trigger-cwe-warning and
- https://github.com/joekiller/typespec-pyclient-snyk-CWE-611/pull/2

### Checklist

- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/Microsoft/typespec/discussions).
- [x] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.