Improvement for “Sharing Position with Friends” in MGE based Web GIS Application

简介:


 

We just taked about the MapGuide Security Hotfix yestoday, and let’s make some improments to make our “Sharing Position With Friends” more secure as well. To avoid cross site script attack, it would be more secure to valide the parameters before pass it into URL.

code goes below, please pay attention to the code marked as bold.

    protected void Page_Load(object sender, EventArgs e)
    {

        // default flexible weblayout
        string webLayout = @"Library://Samples/Sheboygan/FlexibleLayouts/Slate.ApplicationDefinition";
        string viewerPathSchema = @"http://localhost/mapguide/fusion/templates/mapguide/slate/index.html?ApplicationDefinition={1}&SESSION={0}";


        string defaultUser = "Administrator";
        string defaultPassword = "admin";

        Utility utility = new Utility();

        utility.InitializeWebTier(Request);

        MgUserInformation userInfo = new MgUserInformation(defaultUser, defaultPassword);
        MgSiteConnection siteConnection = new MgSiteConnection();
        siteConnection.Open(userInfo);
        MgSite site = siteConnection.GetSite();
        string sessionId = site.CreateSession();

        //store in session for further use
        Session["sessionId"] = sessionId;

        if (Request["X"] != null && Request["Y"] != null && Request["scale"] != null)
        {
            string centerX = Request["X"].ToString();
            string centerY = Request["Y"].ToString();
            string scale = Request["scale"].ToString();

            // validate the parameter to avoid XSS attack
            if (IsValid(centerX) && IsValid(centerY) && IsValid(scale))
            {
                //Generate the new weblayout resource identifier
                webLayout = utility.ChangeInitialViewInWebLayout(webLayout, sessionId, centerX, centerY, scale);
            }

        }

        string viewerPath = string.Format(viewerPathSchema, sessionId, Server.UrlEncode(webLayout));

        Response.Redirect(viewerPath);

    }

    //Only number is valid 
    private bool IsValid(string input)
    {
        return System.Text.RegularExpressions.Regex.IsMatch(input, @"^(-|\+)?\d+(\.\d+)?$");
    }

 

 

cheers!

作者: 峻祁连
邮箱:junqilian@163.com 
出处: http://junqilian.cnblogs.com 
转载请保留此信息。




本文转自峻祁连. Moving to Cloud/Mobile博客园博客,原文链接:http://www.cnblogs.com/junqilian/archive/2010/04/07/1706696.html ,如需转载请自行联系原作者
相关文章
【Azure 应用服务】Web App Service 中的 应用程序配置(Application Setting) 怎么获取key vault中的值
【Azure 应用服务】Web App Service 中的 应用程序配置(Application Setting) 怎么获取key vault中的值
369 0
|
网络协议 Java Shell
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
1289 7
|
应用服务中间件
idea 调试报错 Illegal access: this web application instance has been stopped already.
idea 调试报错 Illegal access: this web application instance has been stopped already.
869 0
|
Cloud Native Java 应用服务中间件
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(1)
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(1)
442 1
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(1)
|
Cloud Native Java 应用服务中间件
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(2)
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(2)
568 1
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(2)
|
Cloud Native Java 应用服务中间件
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(3)
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(3)
554 1
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(3)
|
Cloud Native Java 应用服务中间件
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(4)
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(4)
517 1
带你读《Apache Tomcat的云原生演进》——GraalVM static compilation in web container application(4)
|
XML Java 应用服务中间件
在Web Application中集成CAS登录模块
在Web Application中集成CAS登录模块
348 0
|
前端开发 图形学
Could you provide some examples of when Canvas or SVG would be the better choice for a web application?
Could you provide some examples of when Canvas or SVG would be the better choice for a web application
280 0
|
域名解析 SQL 监控
Web Web Application Firewall
阿里云Web应用防火墙(Web Application Firewall,简称WAF)是一种网络安全服务,用于保护Web应用程序免受常见的Web攻击,如SQL注入、跨站脚本(XSS)和跨站请求伪造(CSRF)等。它可以通过配置规则和策略,识别和拦截恶意流量,从而保护Web应用程序的安全。
547 1