Skip to content

Commit

Permalink
fix(font): only install from the specified folder
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Dec 18, 2024
1 parent ba25c47 commit cb7a5d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/cli/font.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"strings"

"github.com/jandedobbeleer/oh-my-posh/src/font"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
Expand Down Expand Up @@ -47,6 +48,10 @@ This command is used to install fonts and configure the font in your terminal.

terminal.Init(env.Shell())

if !strings.HasPrefix(zipFolder, "/") {
zipFolder += "/"
}

font.Run(fontName, env.Cache(), env.Root(), zipFolder)

return
Expand Down
11 changes: 5 additions & 6 deletions src/font/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,19 @@ func InstallZIP(data []byte, m *main) ([]string, error) {

fonts := make(map[string]*Font)

root := len(m.zipFolder) == 0

for _, file := range zipReader.File {
// prevent zipslip attacks
// https://security.snyk.io/research/zip-slip-vulnerability
// and only process files which are in the specified folder
if strings.Contains(file.Name, "..") || !strings.HasPrefix(file.Name, m.zipFolder) {
// skip folders
if strings.Contains(file.Name, "..") || strings.HasSuffix(file.Name, "/") {
continue
}

fontFileName := path.Base(file.Name)
fontRelativeFileName := strings.TrimPrefix(file.Name, m.zipFolder)

// do not install fonts that are not in the root folder when specified as such
if root && fontFileName != file.Name {
// do not install fonts that are not in the specified installation folder
if fontFileName != fontRelativeFileName {
continue
}

Expand Down

0 comments on commit cb7a5d0

Please sign in to comment.