mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
Small fix for #615
This commit is contained in:
@@ -135,9 +135,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
get("/:userName/_avatar"){
|
get("/:userName/_avatar"){
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).flatMap(_.image).map { image =>
|
getAccountByUserName(userName).flatMap(_.image).map { image =>
|
||||||
outputUploadedRawData(
|
RawData(FileUtil.getMimeType(image), new java.io.File(getUserUploadDir(userName), image))
|
||||||
FileUtil.getMimeType(image),
|
|
||||||
new java.io.File(getUserUploadDir(userName), image))
|
|
||||||
} getOrElse {
|
} getOrElse {
|
||||||
contentType = "image/png"
|
contentType = "image/png"
|
||||||
Thread.currentThread.getContextClassLoader.getResourceAsStream("noimage.png")
|
Thread.currentThread.getContextClassLoader.getResourceAsStream("noimage.png")
|
||||||
|
|||||||
@@ -134,8 +134,10 @@ abstract class ControllerBase extends ScalatraFilter
|
|||||||
if (path.startsWith("http")) path
|
if (path.startsWith("http")) path
|
||||||
else baseUrl + super.url(path, params, false, false, false)
|
else baseUrl + super.url(path, params, false, false, false)
|
||||||
|
|
||||||
/** against XSS */
|
/**
|
||||||
def outputUploadedRawData[DATATYPE](contentType: String, rawData: DATATYPE): DATATYPE = {
|
* Use this method to response the raw data against XSS.
|
||||||
|
*/
|
||||||
|
protected def RawData[T](contentType: String, rawData: T): T = {
|
||||||
if(contentType.split(";").head.trim.toLowerCase.startsWith("text/html")){
|
if(contentType.split(";").head.trim.toLowerCase.startsWith("text/html")){
|
||||||
this.contentType = "text/plain"
|
this.contentType = "text/plain"
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
(Directory.getAttachedDir(repository.owner, repository.name) match {
|
(Directory.getAttachedDir(repository.owner, repository.name) match {
|
||||||
case dir if(dir.exists && dir.isDirectory) =>
|
case dir if(dir.exists && dir.isDirectory) =>
|
||||||
dir.listFiles.find(_.getName.startsWith(params("file") + ".")).map { file =>
|
dir.listFiles.find(_.getName.startsWith(params("file") + ".")).map { file =>
|
||||||
outputUploadedRawData(FileUtil.getMimeType(file.getName), file)
|
RawData(FileUtil.getMimeType(file.getName), file)
|
||||||
}
|
}
|
||||||
case _ => None
|
case _ => None
|
||||||
}) getOrElse NotFound
|
}) getOrElse NotFound
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
if(raw){
|
if(raw){
|
||||||
// Download
|
// Download
|
||||||
defining(JGitUtil.getContentFromId(git, objectId, false).get){ bytes =>
|
defining(JGitUtil.getContentFromId(git, objectId, false).get){ bytes =>
|
||||||
outputUploadedRawData(FileUtil.getContentType(path, bytes), bytes)
|
RawData(FileUtil.getContentType(path, bytes), bytes)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
repo.html.blob(id, repository, path.split("/").toList, JGitUtil.getContentInfo(git, path, objectId),
|
repo.html.blob(id, repository, path.split("/").toList, JGitUtil.getContentInfo(git, path, objectId),
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
val path = multiParams("splat").head
|
val path = multiParams("splat").head
|
||||||
|
|
||||||
getFileContent(repository.owner, repository.name, path).map { bytes =>
|
getFileContent(repository.owner, repository.name, path).map { bytes =>
|
||||||
outputUploadedRawData(FileUtil.getContentType(path, bytes), bytes)
|
RawData(FileUtil.getContentType(path, bytes), bytes)
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user