Skip to content

Commit

Permalink
Ensure illegal repository names are rejected in create-on-push
Browse files Browse the repository at this point in the history
  • Loading branch information
gitblit committed Oct 22, 2012
1 parent 72cb19b commit 3e44b65
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/com/gitblit/GitFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ protected RepositoryModel createRepository(UserModel user, String repository, St
if (isPush) {
if (user.canCreateOnPush(repository)) {
// user is pushing to a new repository
// validate name
if (repository.startsWith("../")) {
logger.error(MessageFormat.format("Illegal relative path in repository name! {0}", repository));
return null;
}
if (repository.contains("/../")) {
logger.error(MessageFormat.format("Illegal relative path in repository name! {0}", repository));
return null;
}

// confirm valid characters in repository name
Character c = StringUtils.findInvalidCharacter(repository);
if (c != null) {
logger.error(MessageFormat.format("Invalid character '{0}' in repository name {1}!", c, repository));
return null;
}

// create repository
RepositoryModel model = new RepositoryModel();
model.name = repository;
model.owner = user.username;
Expand All @@ -213,11 +231,11 @@ protected RepositoryModel createRepository(UserModel user, String repository, St

// create the repository
try {
GitBlit.self().updateRepositoryModel(repository, model, true);
logger.info(MessageFormat.format("{0} created {1} ON-PUSH", user.username, repository));
return GitBlit.self().getRepositoryModel(repository);
GitBlit.self().updateRepositoryModel(model.name, model, true);
logger.info(MessageFormat.format("{0} created {1} ON-PUSH", user.username, model.name));
return GitBlit.self().getRepositoryModel(model.name);
} catch (GitBlitException e) {
logger.error(MessageFormat.format("{0} failed to create repository {1} ON-PUSH!", user.username, repository), e);
logger.error(MessageFormat.format("{0} failed to create repository {1} ON-PUSH!", user.username, model.name), e);
}
} else {
logger.warn(MessageFormat.format("{0} is not permitted to create repository {1} ON-PUSH!", user.username, repository));
Expand Down

0 comments on commit 3e44b65

Please sign in to comment.