mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-12 08:25:50 +01:00
(refs #1523)Eliminate CR and LF in public key
This commit is contained in:
@@ -61,7 +61,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
val sshKeyForm = mapping(
|
val sshKeyForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||||
"publicKey" -> trim(label("Key" , text(required, validPublicKey)))
|
"publicKey" -> trim2(label("Key" , text(required, validPublicKey)))
|
||||||
)(SshKeyForm.apply)
|
)(SshKeyForm.apply)
|
||||||
|
|
||||||
val personalTokenForm = mapping(
|
val personalTokenForm = mapping(
|
||||||
|
|||||||
@@ -159,6 +159,18 @@ 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)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends scalatra-form's trim rule to eliminate CR and LF.
|
||||||
|
*/
|
||||||
|
protected def trim2[T](valueType: SingleValueType[T]): SingleValueType[T] = new SingleValueType[T](){
|
||||||
|
def convert(value: String, messages: Messages): T = valueType.convert(trim(value), messages)
|
||||||
|
|
||||||
|
override def validate(name: String, value: String, params: Map[String, String], messages: Messages): Seq[(String, String)] =
|
||||||
|
valueType.validate(name, trim(value), params, messages)
|
||||||
|
|
||||||
|
private def trim(value: String): String = if(value == null) null else value.replaceAll("\r\n", "").trim
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this method to response the raw data against XSS.
|
* Use this method to response the raw data against XSS.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
val deployKeyForm = mapping(
|
val deployKeyForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||||
"publicKey" -> trim(label("Key" , text(required))), // TODO duplication check in the repository?
|
"publicKey" -> trim2(label("Key" , text(required))), // TODO duplication check in the repository?
|
||||||
"allowWrite" -> trim(label("Key" , boolean()))
|
"allowWrite" -> trim(label("Key" , boolean()))
|
||||||
)(DeployKeyForm.apply)
|
)(DeployKeyForm.apply)
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ object SshUtil {
|
|||||||
val parts = key.split(" ")
|
val parts = key.split(" ")
|
||||||
if (parts.size < 2) {
|
if (parts.size < 2) {
|
||||||
logger.debug(s"Invalid PublicKey Format: ${key}")
|
logger.debug(s"Invalid PublicKey Format: ${key}")
|
||||||
return None
|
None
|
||||||
}
|
} else {
|
||||||
try {
|
try {
|
||||||
val encodedKey = parts(1)
|
val encodedKey = parts(1)
|
||||||
val decode = Base64.getDecoder.decode(Constants.encodeASCII(encodedKey))
|
val decode = Base64.getDecoder.decode(Constants.encodeASCII(encodedKey))
|
||||||
@@ -30,6 +30,7 @@ object SshUtil {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def fingerPrint(key: String): Option[String] =
|
def fingerPrint(key: String): Option[String] =
|
||||||
str2PublicKey(key) map KeyUtils.getFingerPrint
|
str2PublicKey(key) map KeyUtils.getFingerPrint
|
||||||
|
|||||||
Reference in New Issue
Block a user