Commit graph

11611 commits

Author SHA1 Message Date
Damien Elmes
1b882285a5 Treat play_file() and co as internal routines without protection (#4059)
* 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 50b7588231)
2025-06-06 13:23:17 +07:00
Damien Elmes
98253c81cb Bump version 2025-06-04 18:37:18 +07:00
Ren Tatsumoto
5c7eb723b3 Restore ability for add-ons to provide full paths to media (#4054)
* fix #4053

* check if file exist

AJT Japanese needs to play files stored in all possible locations on disk

* check absolute path

* add comment

* check if passed name is basename

* Add a security note to reduce the chance of a regression

* Tweak comment in the non-add-on case

(cherry picked from commit 3ab8c2294d)
2025-06-04 18:33:12 +07:00
Ren Tatsumoto
b5d23f7c0e trim file to basename before creating SoundOrVideoTag (#4057)
* trim file to basename before creating SoundOrVideoTag

* add import

(cherry picked from commit 29e3146e1f)
2025-06-04 18:33:05 +07:00
Damien Elmes
afb3eb7fd8 Restore cert error check
https://forums.ankiweb.net/t/bug-unknown-error-on-startup-anki-25-02/61232/3
(cherry picked from commit 37984233cc)
2025-06-04 16:58:23 +07:00
Damien Elmes
6381f1845f Bump version 2025-06-01 14:10:51 +07:00
Damien Elmes
711db1ee0c Fix mpv being left around on abrupt termination (#4042)
Closes #4015

(cherry picked from commit f81a9bfdfb)
2025-06-01 14:10:28 +07:00
Damien Elmes
f3acf5fe59 Ensure media files are passed relative to the media folder (#4041)
We were (partially) doing this for MpvManager, but not for
Windows' SimpleMpvPlayer. By passing a media file starting
with a special scheme, a malicious actor could have caused a file to
be written to the filesystem on Windows.

Thanks once again to Michael Lappas for the report.

(cherry picked from commit 96ff27d1fb)
2025-06-01 14:10:23 +07:00
Damien Elmes
229819236d Use more secure API key
https://github.com/ankitects/anki/pull/3925#discussion_r2051494659
(cherry picked from commit 757247d424)
2025-06-01 14:10:18 +07:00
Damien Elmes
b02274c255 Bump flask-cors for latest CVEs
(cherry picked from commit 7b4a7dcf18)
2025-06-01 14:06:46 +07:00
Damien Elmes
29192d156a Skip ytdl flag on macOS ARM
Fixes sounds failing to play in the packaged build on macOS.

(cherry picked from commit d3d6bd8ce0)
2025-05-15 19:04:39 +10:00
Damien Elmes
7779fb06fc Bump version 2025-05-15 16:58:12 +10:00
Damien Elmes
6213c9b6f9 Disable YouTube DL in mpv
mpv looks for ytdl on the path, which includes the CWD on Windows.
A malicious shared deck could place an executable called yt-dlp.exe in the
media folder, which mpv would then helpfully invoke the first time
a YouTube link was encountered.

A big thank you to Michael Lappas for the report.

(cherry picked from commit 5080451829)
2025-05-15 16:57:38 +10:00
Adnane Taghi
f161c9ce01 Make URL schemes dialog more ergonomic (#4002)
(originally merged into a PR branch)

* Make URL schemes dialog more ergonomic

* add name to contributors list

* Title Case

* Tweak build instructions so Cursor picks them up

* Use a warning icon for the URL scheme pop-up

* Default to cancelling

(cherry picked from commit f96c8c2ac8)
2025-05-15 16:57:09 +10:00
Damien Elmes
172a4e9863 Add URL scheme whitelist (#3994)
* Add experimental Cursor rules

* Add the ability to customize URL schemes

Closes #3965

(cherry picked from commit 86c89907e7)
2025-05-15 16:56:20 +10:00
Kolby Moroz Liebl
f974c61fa3 Fix dockerimage, by bumping rust version (#3993)
(cherry picked from commit 6427ff3db5)
2025-05-15 16:54:57 +10:00
Damien Elmes
a5c33ad07d Bump version 2025-04-24 15:45:33 +10:00
Aristotelis
9387a85f02 Add add-on scripts to editor CSP (#3942)
(cherry picked from commit 79b19a17a3)
2025-04-24 15:30:45 +10:00
Damien Elmes
9cfd8af34e Fix add-on buttons not working in the editor (#3941)
* Fix add-on buttons not working in the editor

* Ensure old listeners are cleaned up

Thanks to iamllama: https://github.com/ankitects/anki/pull/3941#discussion_r2057066283

(cherry picked from commit 1e74e8e86e)
2025-04-24 15:30:41 +10:00
Damien Elmes
e249b92e48 Bump version again 2025-04-23 17:57:28 +10:00
Damien Elmes
9fc1bc86aa Declare dependency on typing_extensions
venv as things like black depended on it. When running in a packaged
build, it wasn't being included, and Anki was failing to start.

I've added it to the anki module instead of aqt, even though only
the latter is currently using it, so that we don't accidentally introduce
the same bug in the future when using typing_extensions from within
libanki.

(cherry picked from commit 72abb7ec5b)
2025-04-23 17:57:28 +10:00
Damien Elmes
cf97c925e2 Don't check collection size on sync to third-party server
Closes #3936

(cherry picked from commit dd0abfc200)
2025-04-23 17:26:15 +10:00
Damien Elmes
25d5cc5508 Bump version 2025-04-23 16:23:56 +10:00
Damien Elmes
bfc87c0427 Use CSP to block inline JS content in editor (#3939)
* Revert "Sanitize field content in editor"

This reverts commit 1c156905f8.

* Use CSP to block inline JS content in editor

This blocks inline scripts, scripts in the media folder, and
handlers like onclick in the editor. This is nicer than the previous
solution - it doesn't make any permanent changes, and leaves other
content like SVGs alone. Thanks to Nil Admirari for the suggestion.

(cherry picked from commit ddb8573e8d)
2025-04-23 16:23:18 +10:00
Aristotelis
e9dfb7a13d Fix AnkiWebPage not being initialized for default web view kinds (e.g. in add-ons) (#3933)
* add AnkiWebView subclasses for stats, empty cards and find dupes ui

* update ui files to use subclassed webviews instead

* remove superfluous calls to AnkiWebView.set_kind

* Avoid set_kind() race condition in legacy stats webview

Replacing the web view is a hacky workaround, but likely a reasonable compromise for a legacy view that we do not want to maintain a separate Qt form for.

* Slightly refactor AnkiWebView subclass creation and tweak inline comment

+ Extend create_ankiwebview_subclass() with the ability to set any
  init time AnkiWebView argument
+ Introduce some nice-to-haves in terms of static type checking support
  and IDE autocompletion
+ Mark helper function as private to discourage add-on use

* Drop `AnkiWebView.set_kind` completely

There no longer is an Anki-internal use case for changing the web view kind after initializing a web view, and add-ons almost certainly do not have any use for it either.

Given that setting the kind after web view construction can lead  to known race conditions with `domDone` signals, we should remove this method to discourage uses like this in both Anki code and add-on consumers.

There currenty only seems to be one add-on calling `set_kind()`, so this seem like a justifiable API change.

---------

Co-authored-by: llama <100429699+iamllama@users.noreply.github.com>
(cherry picked from commit 5b0f371791)
2025-04-23 16:23:02 +10:00
llama
fa1d6eae84 Fix flashing when opening the stats, empty cards or find dupes dialogs (#3928)
* add AnkiWebView subclasses for stats, empty cards and find dupes ui

* update ui files to use subclassed webviews instead

* remove superfluous calls to AnkiWebView.set_kind

* revert impl

* set page background colour after setPage in AnkiWebView.set_kind

(cherry picked from commit a74fd74631)
2025-04-18 00:10:14 +10:00
Damien Elmes
234fa0c2f4 Latest Rust CVEs
(cherry picked from commit 475fdf04a4)
2025-04-17 11:47:23 +10:00
Damien Elmes
f1b67a2005 Update tokio, crossbeam-channel and cargo-deny
(cherry picked from commit ffbc9a77b7)
2025-04-17 11:46:57 +10:00
Damien Elmes
fa3caa472e Silence a warning about ring
https://github.com/ankitects/anki/issues/3081
(cherry picked from commit b75f2798e6)
2025-04-17 11:46:52 +10:00
Damien Elmes
8d9c8c91b5 Check collection size when syncing
Currently we only check the size on a one-way sync, allowing users
to bypass the limits by incrementally syncing a lot of material.
To prevent this:

- The server now checks if the collection is already oversize,
and forces a one-way sync if it is
- The client checks if the local collection is oversize and refuses
to proceed, so they don't waste time uploading material that will
likely trigger the limit the next time they sync.

(cherry picked from commit 9b5da546be)
2025-04-17 11:42:54 +10:00
Damien Elmes
218757ca46 Update to Rust 1.85
Edition update to follow later

(cherry picked from commit 2727cf39b2)
2025-04-17 11:41:33 +10:00
Damien Elmes
832a1c2c3e Update n2 [action required]
Make sure to run tools/install-n2 after updating to this commit.
n2 have merged in some changes we were previously hosting in a fork,
but the parsing of the flags was altered.

(cherry picked from commit 8e13e6bfc1)
2025-04-17 11:41:11 +10:00
Damien Elmes
670c098af2 Update n2
The flickering on Windows has been improved

(cherry picked from commit 7f8420255d)
2025-04-17 11:40:48 +10:00
Damien Elmes
3f9f3b248e Avoid sending API key for remote resources
Thanks to Abdo for the report

(cherry picked from commit fbb4cf6124)
2025-04-17 11:19:17 +10:00
Damien Elmes
097f9bd138 Add some missed pages/endpoints (thanks to iamllama)
(cherry picked from commit b02111bb2c)
2025-04-17 11:19:11 +10:00
Aristotelis P
269fb073e9 Inject bridge script when profile set-up skipped
Some add-ons fully override AnkiWebPage.__init__ and thus depend on _setupBridge injecting the JS bridge script.

With this change we account for these cases, while giving add-ons the opportunity to look for solutions that do not require overriding AnkiWebPage.__init__ completely.

(cherry picked from commit 2a97b135ee)
2025-04-17 11:19:07 +10:00
Aristotelis P
0467f717ad Provide AnkiWebPage init defaults for existing add-on callers
(cherry picked from commit fd2c95a83e)
2025-04-17 11:18:59 +10:00
Damien Elmes
2fc6b72460 Require an auth token for API access
We were previously inspecting the referrer, but that is spoofable,
and doesn't guard against other processes on the machine.

To accomplish this, we use a request interceptor to automatically
add an auth token to webviews with the right context. Some related
changes were required:

- We avoid storing _page, which was leading to leaks & warning on exit
- At webview creation (or set_kind() invocation), we assign either
an authenticated or unauthenticated web profile.
- Some of our screens initialize the AnkiWebView when calling, e.g.,
aqt.forms.stats.Ui_Dialog(). They then immediately call .set_kind().
This reveals a race condition in our DOM handling code: the webview
initialization creates an empty page with the injected script, which
causes a domDone signal to be sent back. This signal arrives after
we've created another page with .set_kind(), causing our code to think
the DOM is ready when it's not. Then when we try to inject the dynamic
styling, we get an error, as the DOM is not ready yet. In the absence
of better solutions, I've added a hack to set_kind() to deal with this
for now.

(cherry picked from commit 24bca15fd3)
2025-04-17 11:17:47 +10:00
Damien Elmes
82f3778340 Sanitize field content in editor
The editor already strips script tags from fields, but was allowing
through Javascript in things like onclick handlers. We block this now,
as the editor context has access to internal APIs that we don't want to
expose to untrusted third-party code.

(cherry picked from commit 1c156905f8)
2025-04-17 11:16:57 +10:00
Damien Elmes
4bb1698b75 Bump version 2025-04-17 11:16:26 +10:00
Damien Elmes
038d85b1d9 Further tweaks to easy days
The previous commit added word-wrap, but it was not working after I'd
removed some other tweaks I'd made in testing, that I thought were not
required. I ended up switching to standard table columns and a fixed
layout, so that both the column and row headers will wrap properly.
2025-02-11 17:04:58 +07:00
Damien Elmes
348822a14b Quick hack to improve minimum deck options width
Partial fix for #3796
2025-02-11 16:11:43 +07:00
Jarrett Ye
0d9a11c19b
Add margin to the bottom of forgetting curve (#3805) 2025-02-11 15:46:36 +07:00
GithubAnon0000
44e01ea063
Update reviewer.py to prevent custom scheduler js from commenting out py code (#3795)
* Update reviewer.py to prevent custom scheduler js from commenting out py code

* Do not use custom code, but move {js} instead
2025-02-09 16:06:49 +03:00
llama
01c4b48c7d
only change notetype/deck when reopening if no changes to discard (#3798) 2025-02-09 15:58:21 +03:00
Luc Mcgrady
dda5973fdc
Remove forgetting curve radio buttons when only one radio button (#3804) 2025-02-09 15:53:05 +03:00
Damien Elmes
acaeee91fa Bump version 2025-02-06 22:59:27 +07:00
Damien Elmes
20561414b2 Update translations 2025-02-06 22:59:19 +07:00
llama
da8c0f0e9b
clear io image field when resetting in add mode (#3794) 2025-02-06 22:58:49 +07:00
Damien Elmes
f893ec63af Prompt user to apply Windows updates when SSL connection fails
See #3793
2025-02-06 22:57:15 +07:00