Wrong url exception imlemented

main
Inga 🏳‍🌈 15 years ago
parent 7df9f4848e
commit 6456fb4cea
  1. 1
      IISMainHandler/IISMainHandler.csproj
  2. 4
      IISMainHandler/MainHandler.cs
  3. 14
      IISMainHandler/exceptions/WrongUrlException.cs
  4. 15
      IISMainHandler/handlers/StaticHandler.cs
  5. 2
      IISMainHandler/handlers/request/MarkThreadAsReadHandler.cs
  6. 2
      IISMainHandler/handlers/request/MigrateAccountHandler.cs
  7. 9
      IISMainHandler/handlers/response/LegacyPHPHandler.cs
  8. 9
      IISMainHandler/handlers/response/LegacyUploadHandler.cs

@ -51,6 +51,7 @@
<Compile Include="designs\IDesign.cs" />
<Compile Include="designs\Lite.cs" />
<Compile Include="exceptions\RedirectException.cs" />
<Compile Include="exceptions\WrongUrlException.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="HandlersFactory.cs" />
<Compile Include="handlers\AbstractGetHandler.cs" />

@ -28,8 +28,12 @@ namespace FLocal.IISHandler {
}
WebContext context = new WebContext(httpcontext);
try {
ISpecificHandler handler = HandlersFactory.getHandler(context);
handler.Handle(context);
} catch(WrongUrlException) {
(new handlers.WrongUrlHandler()).Handle(context);
}
}
public void ProcessRequest(HttpContext context) {

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Core;
namespace FLocal.IISHandler {
class WrongUrlException : FLocalException {
public WrongUrlException() : base("wrong url") {
}
}
}

@ -18,32 +18,37 @@ namespace FLocal.IISHandler.handlers {
public void Handle(WebContext context) {
if(this.requestParts.Length < 2) {
throw new HttpException(403, "listing not allowed");
//throw new HttpException(403, "listing not allowed");
throw new WrongUrlException();
}
Regex checker = new Regex("^[a-z][0-9a-z\\-_]*(\\.[a-zA-Z]+)?$", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Singleline);
string path = "";
for(int i=1; i<this.requestParts.Length; i++) {
if(!checker.IsMatch(this.requestParts[i])) {
throw new HttpException(400, "wrong url (checker='" + checker.ToString() + "'; string='" + this.requestParts[i] + "'");
//throw new HttpException(400, "wrong url (checker='" + checker.ToString() + "'; string='" + this.requestParts[i] + "'");
throw new WrongUrlException();
}
path += FLocal.Common.Config.instance.DirSeparator + this.requestParts[i];
}
string fullPath = FLocal.Common.Config.instance.dataDir + "Static" + path;
if(!File.Exists(fullPath)) {
throw new HttpException(404, "not found");
//throw new HttpException(404, "not found");
throw new WrongUrlException();
}
FileInfo fileinfo = new FileInfo(fullPath);
if(!fileinfo.FullName.StartsWith(FLocal.Common.Config.instance.dataDir + "Static")) {
throw new HttpException(403, "forbidden");
//throw new HttpException(403, "forbidden");
throw new WrongUrlException();
}
string mime = Util.getMimeByExtension(fileinfo.Extension);
if(mime != null) {
context.httpresponse.ContentType = mime;
} else {
throw new HttpException(403, "wrong file type");
//throw new HttpException(403, "wrong file type");
throw new WrongUrlException();
}
context.httpresponse.Cache.SetExpires(DateTime.Now.AddDays(10));

@ -17,7 +17,7 @@ namespace FLocal.IISHandler.handlers.request {
protected override void _Do(WebContext context) {
Account account = context.session.account;
Thread thread = Thread.LoadById(int.Parse(context.requestParts[2]));
if(!context.requestParts[3].StartsWith("p")) throw new CriticalException("wrong url");
if(!context.requestParts[3].StartsWith("p")) throw new WrongUrlException(); //throw new CriticalException("wrong url");
Post post = Post.LoadById(int.Parse(context.requestParts[3].PHPSubstring(1)));
if(post.thread.id != thread.id) throw new CriticalException("id mismatch");

@ -44,7 +44,7 @@ namespace FLocal.IISHandler.handlers.request {
string userInfo = ShallerGateway.getUserInfoAsString(account.user.name);
Regex regex = new Regex("\\(fhn\\:([a-z0-9]+)\\)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match match = regex.Match(userInfo);
if(!match.Success) throw new FLocalException("key (fhn:***) not found on user info page");
if(!match.Success) throw new FLocalException("key (fhn:***) not found on user info page ( http://forumlocal.ru/showprofile.php?User=" + account.user.name + "&What=login&showlite=l )");
string check = Util.md5(match.Groups[1].Value + " " + Config.instance.SaltMigration + " " + account.id);
if(check != context.httprequest["check"]) throw new FLocalException("Wrong key (fhn:" + match.Groups[1].Value + ")");
if(context.httprequest.Form["password"] != context.httprequest.Form["password2"]) throw new FLocalException("Passwords mismatch");

@ -12,10 +12,12 @@ namespace FLocal.IISHandler.handlers.response {
protected override string getRedirectUrl(WebContext context) {
string[] scriptParts = context.requestParts[0].Split('.');
if(scriptParts.Length != 2) {
throw new FLocalException("wrong url");
//throw new FLocalException("wrong url");
throw new WrongUrlException();
}
if(scriptParts[1].ToLower() != "php") {
throw new FLocalException("wrong url");
//throw new FLocalException("wrong url");
throw new WrongUrlException();
}
switch(scriptParts[0].ToLower()) {
@ -31,7 +33,8 @@ namespace FLocal.IISHandler.handlers.response {
case "showprofile":
return "/User/" + User.LoadByName(context.httprequest.QueryString["User"]).id.ToString() + "/";
default:
throw new NotImplementedException("unknown script " + scriptParts[0]);
//throw new NotImplementedException("unknown script " + scriptParts[0]);
throw new WrongUrlException();
}
}

@ -9,10 +9,10 @@ namespace FLocal.IISHandler.handlers.response {
class LegacyUploadHandler : RedirectGetHandler {
protected override string getRedirectUrl(WebContext context) {
if(context.requestParts.Length != 3) throw new FLocalException("wrong url");
if(context.requestParts.Length != 3) throw new WrongUrlException();// throw new FLocalException("wrong url");
string[] parts = context.requestParts[2].Split('.');
if(parts.Length != 2) throw new FLocalException("wrong url");
if(parts[0].PHPSubstring(0, 4).ToLower() != "file") throw new FLocalException("wrong url");
if(parts.Length != 2) throw new WrongUrlException();// throw new FLocalException("wrong url");
if(parts[0].PHPSubstring(0, 4).ToLower() != "file") throw new WrongUrlException();// throw new FLocalException("wrong url");
int rawFileNum = int.Parse(parts[0].PHPSubstring(4));
int fileNum;
switch(parts[1].ToLower()) {
@ -26,7 +26,8 @@ namespace FLocal.IISHandler.handlers.response {
fileNum = 600000 + rawFileNum;
break;
default:
throw new FLocalException("wrong url");
//throw new FLocalException("wrong url");
throw new WrongUrlException();
}
return "/Upload/Item/" + fileNum + "/";
}

Loading…
Cancel
Save