The probelm with that is I HAVE to use the link: http://www.mysite.com/invo
My boss is adament about it, how do I redirect http://www.mysite.com/invo
Main Topics
Browse All TopicsI need some help with security.
I have a website that stores all invoices in a virtual invoice folder.
Usuers cannot browse the invoices but they can substitute a number and see an invoice not meant for them.
I need to fix this and I am not sure how.
Current;y users log in on the website with a user/pass and that is checked against an access database, they are shown data that belongs to them. When they want to view an invoice, they click on a link and that lionk spawns a script that resides on the server that checks to see if the invoice they are requesting belongs to them.
The link is something like this:
www.mysite.com/getinvoice.
However, if they type
www.mysite.com/invoices/99
they will get the invoice that doesn't belong to them regardless.
I also have to send out notices that tell members that they have new invoices and I have tio list them like so:
www.mysite.com/invoices/99
www.mysite.com/invoices/99
www.mysite.com/invoices/99
that aslo can be "hacked" to show any invoice.
How can I secure this so that they are :
1. Required to go to my login page at least once during the session
2. Denied access to other invoices.
I have a script that checks for that but I do not know how to get it to fire when someone has a direct address.
HELP!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The probelm with that is I HAVE to use the link: http://www.mysite.com/invo
My boss is adament about it, how do I redirect http://www.mysite.com/invo
>The probelm with that is I HAVE to use the link:
Then start authenticating against Windows users and lock everything down with NTFS. Bonus, it's a very secure method.
OR
Use a custom 404 page script to redirect to the authentication script. I would Google some examples for you, but right now my Internet connection is connecting very selectively.... The basic idea is that instead of a HTML page for 404 errors, you put in an ASP script... You detect what the incoming requests are, and when they match a certain pattern (like http://www.mysite.com/invo
Using URL rewrites
http://evolvedcode.net/con
Note this next article uses server.transfer... You would not use that if you want the URL to look like invoices/999999.pdf. Instead, handle the full request in your custom 404 script.
Extending Your Page Names
http://www.asp101.com/arti
Hello Paul
I appreciate the attempt but really, that is the problem I am having in a nutshell.
I HAVE an asp script that will do that, my trouble is I don't know how to fire it from a 404.
I said above,
>>"I have a script that checks for that but I do not know how to get it to fire when someone has a direct address."
How can I get a 404 file to get the variable of the invoice number and store it?
when someone types http://www.mysite.com/invo
One idea is to have the \invoice folder empty and fire the 404 which will strip the invoice number save to a session variable and then redirect to a login.. the login will redirect to the invoice if the login correctly.
Great Idea.. I just dont know how to implement it.
>I HAVE an asp script that will do that, my trouble is I don't know how to fire it from a 404.
What you have is a script that redirects to an unsecured file resource on your server. In order to secure those resources, you have to remove them from the path of the web server, and serve them up as bytes when a request comes in and doesn't find them...
>I don't know how to fire it from a 404.
You do that from IIS. It is explained in the second article.
>How can I get a 404 file to get the variable of the invoice number and store it?
In the custom 404 script, you get the request. That's going to look like this:
<%
Dim strPage, strID
strPage = Request.ServerVariables("S
'Check for URL http://www.mysite.com/invo
If LCase(Left(strPage, Len(strStart))) = strStart And LCase(Right(strPage, Len(strEnd))) = strEnd Then
strID = Mid(strPage, Len(strStart) + 1, Len(strPage) - Len(strStart) - Len(strEnd))
'This is the number. Now check user credentials and get the file
End If
%>
Correction, missing a couple of pieces:
<%
Dim strPage, strID, strStart, strEnd
'Some say QUERY_STRING... I can only get this to work in IIS6.
strPage = Request.ServerVariables("S
'Check for URL /invoices/999999.pdf
strStart = "/invoices/"
strEnd = ".pdf"
If LCase(Left(strPage, Len(strStart))) = strStart And LCase(Right(strPage, Len(strEnd))) = strEnd Then
strID = Mid(strPage, Len(strStart) + 1, Len(strPage) - Len(strStart) - Len(strEnd))
'This is the number. Now get the user credentials, and the file if valid.
End If
%>
Ok, this works... I made a system that does the redirect but the security problem still exists.
That fixed the email issue, now they must login to get an invoice.
but once they get one invoice.. and if they are set to open PDFs in a browser (most are) they now see the location of the invoices in the browser bar and can still change the numbers to get others members invoices, becasue the addres bar shows the normally redirected directory name
arrggh! back to square one!
I guess the problem is how do I get around showing the user what the address to the pdf is?
>are you serious?
>there is no method to allow access and hide the urls?
I've described two methods you can use to secure the files. Both allow you to enter the URL as http://www.mysite.com/invo
Paul
with all respect, I don't see how you have given me two methods.
yes, I can now make sure only autheticated users can access their invoices by using a direct link like:
http://www.mysite.com/invo
But the problem is that once they get to the link http://www.mysite.com/invo
all they need to do is change the 999999.pdf in the browser toolbar to get another file because any 404 redirect script I use in the http://www.mysite.com/invo
in other words
The link they getnin email is: http://www.mysite.com/invo
They go to that link and it fires the 404 script, the script grabs the invoice number (999999) and checks to see if the user is logged in, if not, it redirects to the login which then sends them to the real invoice: http://www.mysite.com/real
The Problem is that on the last step the browser now displays http://www.mysite.com/real
and all they have to do to get another invoice that doesn't belong to them is change the invoice number in the address bar URL
http://www.mysite.com/real
do you see what I mean?
There is no way to hide the last step.. the real address of the pdf file.
unless I missed something???
>The link they getnin email is: http://www.mysite.com/invo
They go to that link and it fires the 404 script, the script grabs the invoice number (999999) and checks to see if the user is logged in, if not, it redirects to the login which then sends them to the real invoice: http://www.mysite.com/real
The problem is that you are sending them to a file resource. That is not what I suggested. There should be no real invoice folder on the web server.
When the 404 script gets the request, it sends back the bytes of the PDF, that are retrieved by the script. Redirecting in any way will cause the URL rewriting to fail and the new address will likely be revealed.
I just ran a test locally, not as a 404 script, but this ASP script sends back a PDF file to the browser. Note that the IIS user has to have read permissions on the PDF folder, or you will get permission errors.
<%
Set objFSO = Server.CreateObject("Scrip
Set objTS = objFSO.OpenTextFile("C:\Te
Response.Buffer = True
Response.ContentType = "applications/vnd.pdf"
Response.AddHeader "Content-disposition", "attachment; filename=test.pdf"
Do While Not objTS.AtEndOfStream
strChunk = objTS.Read(32)
strTmp = ""
For i = 1 to Len(strChunk)
strTmp = strTmp & ChrB(Asc(Mid(strChunk, i, 1)))
Next
Response.BinaryWrite strTmp
Response.Flush
loop
objTS.Close
Set objTS = Nothing
Set objFSO = Nothing
%>
Paul
This is not working for me, I am still getting "text" sent to the browsers.
If you have a moment... Here is the code:
If Session("LOGIN") = False then
' not logged in, send them to login and save some
session("INVOICE")=request
session("referer") =Request.ServerVariables ("URL")
response.redirect("http://
else
INVOICE=Request("INVOICE")
'this checks to see if the request is coming from a link
if INVOICE = "" or ISNULL(INVOICE) then
'otherwise we need to get the invoice number from the saved session varible in login.asp
INVOICE=session("INVOICE")
else
end if
end if
INVOICEstrip=replace(INVOI
set objConn = server.createobject("adodb
objConn.open "Provider=Microsoft.Jet.OL
"Data Source=c:\databases\;" & _
"Extended Properties=""DBASE IV;"";"
sqlstat="SELECT * FROM MyDatabase WHERE INVOICE= '"+INVOICEstrip+"' and ACCO='" + session("user") + "'"
set rs = objConn.execute (sqlstat)
if Not rs.eof then'
while not.rs.eof
pdf = INVOICEstrip
Set objFSO = Server.CreateObject("Scrip
Set objTS = objFSO.OpenTextFile("C:\in
Response.Buffer = True
Response.ContentType = "applications/vnd.pdf"
Response.AddHeader "Content-disposition", "attachment; filename=" & INVOICEstrip & ".pdf"
Do While Not objTS.AtEndOfStream
strChunk = objTS.Read(32)
strTmp = ""
For i = 1 to Len(strChunk)
strTmp = strTmp & ChrB(Asc(Mid(strChunk, i, 1)))
Next
Response.BinaryWrite strTmp
Response.Flush
loop
objTS.Close
Set objTS = Nothing
Set objFSO = Nothing
rs.movenext
wend
else
response.redirect("99999z.
end if
I even tried this totally seperate from any other code to see what I would get and I still get the text....
I know the "text" is the actual pdf, but the browser is not seeing it as a pdf.
yes.. full
nothing else above or below.
I am testing a copy to temp then redirect directory solution right now and although it works like a charm, it still isn't the cats meow. I have to dump all the copied pdfs on a regular basis and thats not a great solution.
I would love to get this working correctly, but I have almost lost hope.
:<
Does this cause the same problem?
http://notbono.dnsalias.co
Business Accounts
Answer for Membership
by: PaulHewsPosted on 2007-08-09 at 12:36:04ID: 19665192
>Current;y users log in on the website with a user/pass and that is checked against an access database
ting.FileS ystemObjec t") .MapPath(" InvoiceFol der/" & strFile))
If users log in using windows domain usernames (turn off anonymous access in IIS, and use Basic Authentication with SSL over the Internet or Integrated Windows Authentication on your local network) then you can use Windows NTFS permissions on separate files or folders to control who has access to what.
The other way is to restrict access to the files and only allow download through the ASP script. So the files will be in a folder that is restricted from your web site, but you can validate the download through a script similar to this:
if Check(strUser, strFilename) = True Then 'Whatever logic you have to validate users for filenames...
Set objFSO = Server.CreateObject("Scrip
Set objTS = objFSO.OpenTextFile(Server
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.AddHeader "Content-disposition", "attachment; filename=" & strFile
Do While Not objTS.AtEndOfStream
strChunk = objTS.Read(32)
strTmp = ""
For i = 1 to Len(strChunk)
strTmp = strTmp & ChrB(Asc(Mid(strChunk, i, 1)))
Next
Response.BinaryWrite strTmp
Response.Flush
loop
objTS.Close
Set objTS = Nothing
Set objFSO = Nothing
Else
Response.Redirect "noaccess.html"
End If