1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . ComponentModel ;
4
+ using System . IO ;
4
5
using System . Linq ;
5
6
using System . Runtime . InteropServices ;
6
7
using System . Runtime . InteropServices . ComTypes ;
14
15
15
16
namespace FlashpointSecurePlayer {
16
17
public class CustomSecurityManager : InternetInterfaces . IServiceProvider , InternetInterfaces . IInternetSecurityManager {
18
+ private const string FLASH_EXTENSION = ".SWF" ;
19
+
20
+ // https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms537182(v=vs.85)?redirectedfrom=MSDN
17
21
public CustomSecurityManager ( WebBrowser _WebBrowser ) {
18
22
InternetInterfaces . IServiceProvider webBrowserServiceProviderInterface = _WebBrowser . ActiveXInstance as InternetInterfaces . IServiceProvider ;
19
23
IntPtr profferServiceInterfacePointer = IntPtr . Zero ;
@@ -63,19 +67,23 @@ int InternetInterfaces.IInternetSecurityManager.MapUrlToZone([MarshalAs(Unmanage
63
67
// behave like local intranet
64
68
pdwZone = 1 ;
65
69
70
+ // don't map zone for file:// URLs, that's outside the proxy
66
71
if ( ( dwFlags & MUTZ_ISFILE ) == MUTZ_ISFILE ) {
67
72
return INET_E_DEFAULT_ACTION ;
68
73
}
69
74
75
+ // error if URL is null
70
76
if ( pwszUrl == null ) {
71
77
return E_INVALIDARG ;
72
78
}
73
79
80
+ // unescape URL if needed
74
81
if ( ( dwFlags & MUTZ_DONT_UNESCAPE ) != MUTZ_DONT_UNESCAPE ) {
75
82
try {
76
83
pwszUrl = Uri . UnescapeDataString ( pwszUrl ) ;
77
84
} catch ( ArgumentNullException ) {
78
- return INET_E_DEFAULT_ACTION ;
85
+ // error if URL is null
86
+ return E_INVALIDARG ;
79
87
}
80
88
}
81
89
@@ -95,14 +103,31 @@ int InternetInterfaces.IInternetSecurityManager.GetSecurityId([MarshalAs(Unmanag
95
103
int InternetInterfaces . IInternetSecurityManager . ProcessUrlAction ( [ MarshalAs ( UnmanagedType . LPWStr ) ] string pwszUrl , uint dwAction , out uint pPolicy , uint cbPolicy , byte pContext , uint cbContext , uint dwFlags , uint dwReserved ) {
96
104
pPolicy = URLPOLICY_DISALLOW ;
97
105
106
+ if ( cbPolicy < Marshal . SizeOf ( pPolicy . GetType ( ) ) ) {
107
+ return S_FALSE ;
108
+ }
109
+
110
+ // don't process file:// URLS, they are outside the proxy
98
111
if ( ( dwFlags & PUAF_ISFILE ) == PUAF_ISFILE ) {
99
112
return INET_E_DEFAULT_ACTION ;
100
113
}
101
114
115
+ // error if URL is null
102
116
if ( pwszUrl == null ) {
103
117
return E_INVALIDARG ;
104
118
}
105
119
120
+ try {
121
+ if ( Path . GetExtension ( new Uri ( pwszUrl ) . LocalPath ) . ToUpper ( ) == FLASH_EXTENSION ) {
122
+ if ( dwAction == URLACTION_ACTIVEX_TREATASUNTRUSTED ) { // don't trust Flash ActiveX Controls
123
+ pPolicy = URLPOLICY_ALLOW ;
124
+ }
125
+ return S_OK ;
126
+ }
127
+ } catch {
128
+ return S_FALSE ;
129
+ }
130
+
106
131
pwszUrl = pwszUrl . ToLower ( ) ;
107
132
108
133
if ( pwszUrl . IndexOf ( "http://" ) != 0 && pwszUrl . IndexOf ( "https://" ) != 0 && pwszUrl . IndexOf ( "ftp://" ) != 0 ) {
@@ -113,7 +138,7 @@ int InternetInterfaces.IInternetSecurityManager.ProcessUrlAction([MarshalAs(Unma
113
138
return INET_E_DEFAULT_ACTION ;
114
139
}
115
140
116
- if ( dwAction == URLACTION_ACTIVEX_TREATASUNTRUSTED || // trust ActiveX Controls always
141
+ if ( dwAction == URLACTION_ACTIVEX_TREATASUNTRUSTED || // trust other ActiveX Controls
117
142
dwAction == URLACTION_HTML_MIXED_CONTENT || // block HTTPS content on HTTP websites for Flashpoint Proxy
118
143
dwAction == URLACTION_CLIENT_CERT_PROMPT || // don't allow invalid certificates
119
144
dwAction == URLACTION_AUTOMATIC_ACTIVEX_UI || // do not display the install dialog for ActiveX Controls
0 commit comments