Skip to content

WASM - Check permissions before reading or writing to clipboard - #21573

Merged
MrJul merged 9 commits into
masterfrom
wasm_clipboard_permission
Jun 23, 2026
Merged

MrJul merged 9 commits into
masterfrom
wasm_clipboard_permission

Conversation

@emmauss

@emmauss emmauss commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

What does the pull request do?

Adds checks before reading or writing to clipboard on wasm. UnauthorizedAccessException will be thrown if permission is not granted.

What is the current behavior?

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

Fixes the cause of #21530 . This PR doesn't help with intercepting clipboard.
Fixes #21568

@emmauss
emmauss requested a review from MrJul June 12, 2026 14:34
@MrJul MrJul added bug backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jun 12, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066353-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Comment on lines +23 to +26
catch(JSException ex)
{
throw new UnauthorizedAccessException(ex.Message);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pass original exception as InnerException

Comment thread src/Browser/Avalonia.Browser/ClipboardImpl.cs Outdated
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066355-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066385-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Comment thread src/Browser/Avalonia.Browser/webapp/modules/avalonia/input.ts Outdated
@emmauss

emmauss commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Updated. Removed explicit permission check, but instead check for NotAllowedError.

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066419-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Comment thread src/Browser/Avalonia.Browser/webapp/modules/avalonia/generalHelpers.ts Outdated
Comment thread src/Browser/Avalonia.Browser/Interop/GeneralHelpers.cs Outdated
Comment thread src/Browser/Avalonia.Browser/webapp/modules/avalonia/input.ts Outdated
@emmauss

emmauss commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Addressed @MrJul review.

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066610-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Comment thread src/Browser/Avalonia.Browser/ClipboardImpl.cs Outdated
Comment thread src/Avalonia.Controls/TextBox.cs Outdated

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-tested, works as expected. LGTM!

@MrJul
MrJul enabled auto-merge June 23, 2026 09:41
@MrJul
MrJul added this pull request to the merge queue Jun 23, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066786-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Merged via the queue into master with commit b84f5db Jun 23, 2026
11 checks passed
@MrJul
MrJul deleted the wasm_clipboard_permission branch June 23, 2026 11:46
MrJul added a commit to MrJul/Avalonia that referenced this pull request Jun 23, 2026
…oniaUI#21573)

* check permissions before reading or writing to clipboard

* throw UnauthorizedAccessException when permission is not granted for clipboard

* handle unauthorized access exceptions for clipboard in textbox

* check only for denied errors on clipboard

* addressed review

* wasm - use marshal methods instead when reading clipboard

* log unauthorized read clipboard  error

* Improve logging

* Also log in MaskedTextBox

---------

Co-authored-by: Julien Lebosquain 
@MrJul MrJul added backported-12.0.x and removed backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jun 23, 2026
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.

navigator.clipboard.read and navigator.clipboard.readText can throw NotAllowedError

5 participants