Skip to content

Conversation

@dae
Copy link
Member

@dae dae commented Jun 5, 2025

Our code and add-ons need a way to play audio from arbitrary locations. I propose we treat the _tag API as suitable for user input, and the _file API for internal use.

Closes #4058

Our code and add-ons need a way to play audio from arbitrary locations.
I propose we treat the _tag API as dangerous, and the _file API as
trusted.

Related: #4058
@dae dae mentioned this pull request Jun 5, 2025
qt/aqt/sound.py Outdated
"""Play the provided path.
SECURITY: Filename may be an arbitrary path. For content coming from a collection,
use play_tag() instead."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

To me, this implies play_tags() does some validation and enforces a media path, while it's actually exactly the same under the hood.

@abdnh
Copy link
Collaborator

abdnh commented Jun 5, 2025

This looks like a better approach for add-ons. If we want to leave validation to add-ons dealing with user input, a note about os.path.basename() in the docstrings would be nice.

@dae
Copy link
Member Author

dae commented Jun 6, 2025

If my change wasn't what you intended, please feel free to push a follow-up :-)

@dae dae merged commit 50b7588 into main Jun 6, 2025
1 check was pending
dae added a commit that referenced this pull request Jun 6, 2025
* Treat play_file() and co as internal routines without protection

Our code and add-ons need a way to play audio from arbitrary locations. I propose we treat the _tag API as suitable for user input, and the _file API for internal use.

* Mention basename in the *_file() paths

(cherry picked from commit 50b7588)
@luc-vocab
Copy link

This was possibly the cause of Vocab-Apps/anki-hyper-tts#282 as well ?

@abdnh
Copy link
Collaborator

abdnh commented Jun 18, 2025

I see some av_player.play_file/insert_file calls in the add-on's code, so that's probably it if HyperTTS is playing audio files not in the media directory.

@luc-vocab
Copy link

@abdnh can you elaborate on this ?

@dae
Copy link
Member Author

dae commented Jun 19, 2025

It was a bug in .6. It should be fixed in .7 already, so please test with that / ask the user to.

@dae dae deleted the soundfix branch June 20, 2025 10:04
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.

4 participants