Skip to content

Commit 1257d43

Browse files
Bwkolunny
authored andcommitted
Add a reserved path check to the wiki (#720)
1 parent f9a3aa8 commit 1257d43

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

models/wiki.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import (
2121
"code.gitea.io/gitea/modules/sync"
2222
)
2323

24-
var wikiWorkingPool = sync.NewExclusivePool()
24+
var (
25+
reservedUncycloPaths = []string{"_pages", "_new", "_edit"}
26+
wikiWorkingPool = sync.NewExclusivePool()
27+
)
2528

2629
// ToUncycloPageURL formats a string to corresponding wiki URL name.
2730
func ToUncycloPageURL(name string) string {
@@ -88,8 +91,22 @@ func discardLocalUncycloChanges(localPath string) error {
8891
return discardLocalRepoBranchChanges(localPath, "master")
8992
}
9093

94+
// pathAllowed checks if a wiki path is allowed
95+
func pathAllowed(path string) error {
96+
for i := range reservedUncycloPaths {
97+
if path == reservedUncycloPaths[i] {
98+
return ErrUncycloAlreadyExist{path}
99+
}
100+
}
101+
return nil
102+
}
103+
91104
// updateUncycloPage adds new page to repository wiki.
92105
func (repo *Repository) updateUncycloPage(doer *User, oldUncycloPath, wikiPath, content, message string, isNew bool) (err error) {
106+
if err = pathAllowed(wikiPath); err != nil {
107+
return err
108+
}
109+
93110
wikiWorkingPool.CheckIn(com.ToStr(repo.ID))
94111
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID))
95112

0 commit comments

Comments
 (0)