Index: core/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- core/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java	(revision 28841)
+++ core/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java	(working copy)
@@ -1804,8 +1804,16 @@
             }
         }
 
-        String content = getResourceContent("/templates/" + template);
-        return XWikiVelocityRenderer.evaluate(content, "/templates/" + template,
+        // XWIKI-2580 prevent inclusion of templates from other directories
+        template = URI.create("/templates/" + template).normalize().toString();
+        if (!template.startsWith("/templates/")) {
+            LOG.warn("Illegal access, tried to use file [" + template + "] as a template."
+                + " Possible break-in attempt!");
+            return "";
+        }
+
+        String content = getResourceContent(template);
+        return XWikiVelocityRenderer.evaluate(content, template,
             (VelocityContext) context.get("vcontext"), context);
     }
 
