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

Add yaml dumper that converts numpy to native #588

Merged
merged 1 commit into from
Nov 29, 2023
Merged

Conversation

psavery
Copy link
Collaborator

@psavery psavery commented Nov 29, 2023

We want to make sure we avoid unsafe yaml dumps, which can be used to dump arbitrary Python objects, because want to avoid unsafe yaml loads, which can execute arbitrary Python code and is a security risk.

It looks like we were sometimes dumping numpy objects (as can be seen in HEXRD/hexrdgui#1625), and these cannot be loaded without performing an unsafe load.

This PR changes all regular yaml dumps to safe_dump to ensure this does not happen. It also adds a custom dumper that converts numpy types to native types while dumping. This is used when saving the instrument config currently (but we can use it in other places too, if needed).

Fixes: HEXRD/hexrdgui#1625

We want to make sure we avoid unsafe yaml dumps, which can be used to
dump arbitrary Python objects, because want to avoid unsafe yaml loads,
which can execute arbitrary Python code and is a security risk.

It looks like we were sometimes dumping numpy objects (as can be seen
in HEXRD/hexrdgui#1625), and these cannot be loaded without performing
an unsafe load.

This PR changes all regular yaml dumps to `safe_dump` to ensure this does
not happen. It also adds a custom dumper that converts numpy types to
native types while dumping. This is used when saving the instrument config
currently (but we can use it in other places too, if needed).

Fixes: HEXRD/hexrdgui#1625

Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
@psavery psavery merged commit ff96462 into master Nov 29, 2023
6 checks passed
@psavery psavery deleted the yaml-dumper branch November 29, 2023 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loading yamls in gui /hexrd
2 participants