Stopping WebBrowser from navigating to local files. 
Author Message
 Stopping WebBrowser from navigating to local files.

I have a custom webbrowser control. The user can surf the net as usual
but if they c:\ in the navigation ComboBox, they can get to the root of
the winNt box and subsequently any directory on the machine. What are my
possible solutions for this? Also if I block all access to the local
files, I still need to keep one directory available for supporting files,
i.e., local .html files and text files that are read at run-time.
Basically the entire file system needs to be invisible to the webbrowser
control except one folder, c:\supportFiles\

Thanks for any help

Jerry



Sun, 13 Oct 2002 03:00:00 GMT  
 Stopping WebBrowser from navigating to local files.
You can monitor the URL in the BeforeNavigate2 event of the WebBrowser
control.  Just don't allow them if they are about to navigate to a local
file not located in your supportFiles directory.

--
Regards,

Gregory Silvano
http://www.codehound.com
Free Internet Search Engine for VB Developers


Quote:
> I have a custom webbrowser control. The user can surf the net as usual
> but if they c:\ in the navigation ComboBox, they can get to the root of
> the winNt box and subsequently any directory on the machine. What are my
> possible solutions for this? Also if I block all access to the local
> files, I still need to keep one directory available for supporting files,
> i.e., local .html files and text files that are read at run-time.
> Basically the entire file system needs to be invisible to the webbrowser
> control except one folder, c:\supportFiles\

> Thanks for any help

> Jerry



Sun, 13 Oct 2002 03:00:00 GMT  
 Stopping WebBrowser from navigating to local files.
Hello,

I posted some code below. I found if I restrict the user from the get go,
I don't have a problem. Logically this works but I feel that I went
around the world to get to it. My concern is, what if there's something
is included in the navigating in time? An example, "http_new://". If
something new comes out or I missed something, this browser will be
obsolete in time. Does anyone have a better logic to tackle this? Thanks
again.

Jerry

Here's the code:

Private Sub wbMain_BeforeNavigate2(index As Integer, ByVal pDisp As
Object, URL As Variant, Flags As Variant, TargetFrameName As Variant,
PostData As Variant, Headers As Variant, Cancel As Boolean)

If LCase(Left(URL, 16)) = "c:\source_files" Or _
LCase(Left(URL, 7)) = "http://" Or _
LCase(Left(URL, 8)) = "https://" Or _
LCase(Left(URL, 7)) = "mailto:" Or _
LCase(Left(URL, 6)) = "ftp://" Or _
LCase(Left(URL, 24)) = "file:///c:/source_files" Or _
LCase(Left(URL, 11)) = "javascript:" Then

        wb1.navigate URL
Else
        Cancel=True
End If



Quote:
> You can monitor the URL in the BeforeNavigate2 event of the WebBrowser
> control.  Just don't allow them if they are about to navigate to a local
> file not located in your supportFiles directory.

> --
> Regards,

> Gregory Silvano
> http://www.codehound.com
> Free Internet Search Engine for VB Developers



> > I have a custom webbrowser control. The user can surf the net as usual
> > but if they c:\ in the navigation ComboBox, they can get to the root of
> > the winNt box and subsequently any directory on the machine. What are my
> > possible solutions for this? Also if I block all access to the local
> > files, I still need to keep one directory available for supporting files,
> > i.e., local .html files and text files that are read at run-time.
> > Basically the entire file system needs to be invisible to the webbrowser
> > control except one folder, c:\supportFiles\

> > Thanks for any help

> > Jerry



Mon, 14 Oct 2002 03:00:00 GMT  
 Stopping WebBrowser from navigating to local files.
Save the "approved" strings in an INI file, the Registry, or a database.
Load them up at runtime into an array and loop through the array instead of
using the logic below.  You can have 1,000 things in the array and the code
won't change at all:

for icount = lbound(myarray) to ubound(myarray)
    if ucase(left(url,len(myarray(icount)))) = ucase(myarray(icount)) then
        bOK = true
        exit for
    end if
next icount

if bOK then navigate...

This was written in OE, so the syntax may be off, but you get the idea.  Of
course, this is just streamlining the original brute-force method.  There
may be (and probably is) a better alternative altogether.  I just can't
think of one right now.  ;)

--
Regards,

Gregory Silvano
http://www.codehound.com
Free Internet Search Engine for VB Developers


Quote:
> Hello,

> I posted some code below. I found if I restrict the user from the get go,
> I don't have a problem. Logically this works but I feel that I went
> around the world to get to it. My concern is, what if there's something
> is included in the navigating in time? An example, "http_new://". If
> something new comes out or I missed something, this browser will be
> obsolete in time. Does anyone have a better logic to tackle this? Thanks
> again.

> Jerry

> Here's the code:

> Private Sub wbMain_BeforeNavigate2(index As Integer, ByVal pDisp As
> Object, URL As Variant, Flags As Variant, TargetFrameName As Variant,
> PostData As Variant, Headers As Variant, Cancel As Boolean)

> If LCase(Left(URL, 16)) = "c:\source_files" Or _
> LCase(Left(URL, 7)) = "http://" Or _
> LCase(Left(URL, 8)) = "https://" Or _
> LCase(Left(URL, 7)) = "mailto:" Or _
> LCase(Left(URL, 6)) = "ftp://" Or _
> LCase(Left(URL, 24)) = "file:///c:/source_files" Or _
> LCase(Left(URL, 11)) = "javascript:" Then

> wb1.navigate URL
> Else
> Cancel=True
> End If



> > You can monitor the URL in the BeforeNavigate2 event of the WebBrowser
> > control.  Just don't allow them if they are about to navigate to a local
> > file not located in your supportFiles directory.

> > --
> > Regards,

> > Gregory Silvano
> > http://www.codehound.com
> > Free Internet Search Engine for VB Developers



> > > I have a custom webbrowser control. The user can surf the net as usual
> > > but if they c:\ in the navigation ComboBox, they can get to the root
of
> > > the winNt box and subsequently any directory on the machine. What are
my
> > > possible solutions for this? Also if I block all access to the local
> > > files, I still need to keep one directory available for supporting
files,
> > > i.e., local .html files and text files that are read at run-time.
> > > Basically the entire file system needs to be invisible to the
webbrowser
> > > control except one folder, c:\supportFiles\

> > > Thanks for any help

> > > Jerry



Mon, 14 Oct 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Stopping WebBrowser from navigating to local files.

2. Stopping WebBrowser from navigating to local files.

3. Stopping WebBrowser from navigating to local files.

4. Stopping WebBrowser from navigating to local files.

5. Stopping WebBrowser from navigating to local files.

6. Using WebBrowser ctl to navigate to a local file

7. navigating webBrowser to a executible resource file?

8. Newbie: Linking local files to WebBrowser

9. Webbrowser control for local .htm files

10. Help: prevent webbrowser ctrl getting access on local file system

11. GURU needed: VB6 webbrowser: Detect Navigation to local File system -- suppress new window

12. NewWindow navigating local resource or ftp

 

 
Powered by phpBB® Forum Software