{"record":{"id":"8a04880f69ee41cf","repo":"dotnet/wpf","slug":"unauthorizedaccessexception","errorCode":null,"errorMessage":"UnauthorizedAccessException","messagePattern":"UnauthorizedAccessException","errorType":"exception","errorClass":"UnauthorizedAccessException","httpStatus":null,"severity":"warning","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/MSAANativeProvider.cs","lineNumber":962,"sourceCode":"            }\n            else if (idProp == AutomationElement.HasKeyboardFocusProperty)\n            {\n                return _acc.IsFocused;\n            }\n            else if (idProp == AutomationElement.IsOffscreenProperty)\n            {\n                return _acc.IsOffScreen;\n            }\n            return null;\n        }\n\n        // overridable method used by value pattern to retrieve the value.\n        protected virtual string GetValue()\n        {\n            // if this is a password edit control then throw an exception\n            if (_acc.IsPassword)\n            {\n                throw new UnauthorizedAccessException();\n            }\n\n            return _acc.Value;\n        }\n\n        // overridable method used by value pattern to set the value.\n        protected virtual void SetValue(string val)\n        {\n            _acc.Value = val;\n        }\n\n        #endregion Protected Methods\n\n        //------------------------------------------------------\n        //\n        //  Private Methods\n        //\n        //------------------------------------------------------","sourceCodeStart":944,"sourceCodeEnd":980,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/MSAANativeProvider.cs#L944-L980","documentation":"The value pattern's GetValue on MSAA-backed elements deliberately throws UnauthorizedAccessException when the underlying accessible object reports IsPassword, so automation clients cannot read password content. This is an intentional privacy/security guard, not an environment failure.","triggerScenarios":"Calling ValuePattern.Value (which invokes the virtual GetValue) on a password edit control (ES_PASSWORD style / accessible role reporting a password field).","commonSituations":"Test frameworks trying to log or assert the content of a password box; automation scripts scraping login dialogs; attempting to snapshot all field values in a form including credentials.","solutions":["Do not attempt to read password field values; assert on other signals (field presence, masked length) instead","Check the IsPassword property / IsOffscreen style indicators before retrieving Value and skip password fields","Inject test credentials via configuration and verify behavior, not stored values","Catch UnauthorizedAccessException around Value retrieval and treat password fields as unreadable by design"],"exampleFix":"// before\nvar text = valuePattern.Current.Value;\n// after\nstring text = null;\nif (element.TryGetCurrentPattern(ValuePattern.Pattern, out var p))\n{\n    try { text = ((ValuePattern)p).Current.Value; }\n    catch (UnauthorizedAccessException) { text = \"<password field: value withheld>\"; }\n}","handlingStrategy":"try-catch","validationCode":"bool isPassword = element.Current.HelpText?.Contains(\"password\") == true || /* check app-specific marker */ false;","typeGuard":null,"tryCatchPattern":"try { value = valuePattern.Current.Value; }\ncatch (UnauthorizedAccessException) { value = \"<withheld: password field>\"; }","preventionTips":["Never read or log password field values in automation","Skip elements flagged as password when snapshotting forms","Assert credentials via behavior, not stored values"],"tags":["ui-automation","security","password"],"backgroundTag":"permission-denied","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}