Assume a very unfriendly user.<div><br></div><div>He gives a request like:</div><div><br></div><div>/~jschama/../jschama/../testdir1/../jschama/testdir/subdir/file, even more worse.</div><div><br></div><div>Now we begin to transfer that to a valid request.(actually it is valid, but the program doesn't know)</div>
<div>Assuming that testdir1 does not exist.</div><div><br></div><div>If we check this request step by step, when we achieve /~jschama/../jschama/..testdir1/, the chdir() or access() will fail because there is no such dir in the system.</div>
<div>But actually it is a valid request because we have a .. following by testdir1/ . So I don't think we can process the request step by step.</div><div>We need to process the request URL as a whole string. </div><div>
<br></div><div>But the question is,how can we know which part is the requested part. </div><div>As you mentioned </div><div>If we have a request like /~jschama/../testdir/file, we take the testdir/file under the server root.</div>
<div>For this example, we will take the testdir/subdir/file. </div><div>So this is the case that testdir/subdir/file is under /home/jschama.</div><div>But if the request is like /~jschama/../jschama/../testdir1/../jschama/../testdir/../../lib/subdir/file (equals to /lib/subdir/file). It also may be /home/subdir/subsubdir/file after processing the URL.</div>
<div>By looking at it, we know that we need to process /lib/subdir/file in the server root (./usr/htdocs).</div><div>The question is:</div><div>How can the program tell which part is the relative path of the file to be processed? </div>
<div>(The same problem with the normal request, and for the normal request,even more complicated case may happen.)</div><div><br></div><div>Can we just make it easy by just picking the file name, ignoring the directories.</div>
<div>For example, we just take the "file", then check the whole directory " /~jschama/../jschama/../testdir1/../jschama/../testdir/../subdir" is in or out the root.</div><div>If in, then process the corresponding file, if out, we just make the request like ./usr/htdocs/file(ignoring the directory)</div>
<div><br></div><div>Thank</div><div>Chao</div><div><br></div><div><br></div><div><br><div class="gmail_quote">2012/12/5 Jan Schaumann <span dir="ltr"><<a href="mailto:jschauma@stevens.edu" target="_blank">jschauma@stevens.edu</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">ccui1 <<a href="mailto:ccui1@stevens.edu">ccui1@stevens.edu</a>> wrote:<br>
<br>
> The request like<br>
> /~jschama/ we transfer that to /home/jschama/sws/.<br>
><br>
> If we get a request like /~jschama/testdir/ we transfer that into<br>
> /home/jschama/sws/testdir/.<br>
><br>
> Does that means when we get such kind of request, we find the files or<br>
> directories under /home/jschama/sws/?<br>
<br>
</div>Correct.<br>
<div class="im"><br>
> What if we get a request like<br>
> /~jschama/../testdir/file ?<br>
<br>
</div>Here, you are attempting to go one directory above the ~jschauma<br>
directory, ie /testdir/file.  This is then resolved relative to the<br>
servers document root just as if the request had been for<br>
"/testdir/file".<br>
<div class="im"><br>
> Shall we just pick the requested file name and find the same file name<br>
> under ./usr/htdocs/ ?<br>
<br>
</div>If your server was invoked with "./usr/htdocs" as the document root to<br>
serve content from, yes.<br>
<div class="im"><br>
> Why do our web server support such kind of request?<br>
> If I run this server, it means others can see the information in my<br>
> personal folder.<br>
<br>
</div>Correct.  If you decide to run a web server serving the contents of a<br>
specific directory under your home directory, then other people can<br>
access contents of that specific directory under your home directory.<br>
<div class="im"><br>
> How can that be useful for a web server?<br>
<br>
</div>Think about it.  How do you think the course website works?<br>
<br>
<a href="http://www.cs.stevens.edu/~jschauma/631/" target="_blank">http://www.cs.stevens.edu/~jschauma/631/</a><br>
<br>
If we want to allow different users on a system to have their own<br>
websites with content they control, we can't have that data in the<br>
document root -- otherwise, all users on the systems would require write<br>
access there.<br>
<br>
<br>
For example, if you would like to have your own website under<br>
<a href="http://www.cs.stevens.edu/~ccui/" target="_blank">http://www.cs.stevens.edu/~ccui/</a>, then you can create a directory named<br>
"cs_html" on <a href="http://linux-lab.cs.stevens.edu" target="_blank">linux-lab.cs.stevens.edu</a>, and any files you place there<br>
will be available on the above URL.  Here, the web server uses the<br>
"cs_html" directory to perform the per-user translation.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Jan<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
cs631apue mailing list<br>
<a href="mailto:cs631apue@lists.stevens.edu">cs631apue@lists.stevens.edu</a><br>
<a href="https://lists.stevens.edu/cgi-bin/mailman/listinfo/cs631apue" target="_blank">https://lists.stevens.edu/cgi-bin/mailman/listinfo/cs631apue</a><br>
</div></div></blockquote></div><br></div>