Skip to content

Commit

Permalink
Add checks for download links against forged requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmandourah committed Oct 19, 2024
1 parent f2e172c commit f8e405e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion gamescollection/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ type collect struct {

// New create a new collection
func New(config repository.Config) repository.Collection {
return &collect{
c := &collect{
config: config,
}
c.games.Headers = append(c.games.Headers, "Tinshop-ng: " + "*")
return c
}

// Load ensure that necessary data is loaded
Expand Down
1 change: 1 addition & 0 deletions repository/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type GameType struct {
ThemeBlackList []string `json:"themeBlackList,omitempty"`
// Removing the titledb for the resulted json.
Titledb map[string]TitleDBEntry `json:"-"`
Headers []string `json:"headers"`
}

// GameFileType stores the fields needed for game files
Expand Down
20 changes: 19 additions & 1 deletion security.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,36 @@ func (s *TinShop) TinfoilMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Verify all headers
headers := r.Header


//Skip security checks if Nosecurity is true
if s.Shop.Config.DebugNoSecurity() {
next.ServeHTTP(w, r)
return
}

// Checks for download links
if strings.Contains(r.RequestURI, "/games") {
//insuring basic headers available while downloading a game
if headers["Hauth"] == nil || headers["Uauth"] == nil || headers["Tinshop-Ng"] == nil {
log.Println("An attempt to download one of your content from non-Tinfoil Client was Blocked.", r.RemoteAddr)
return
}

//Hauth check
if s.Shop.Config.Get_Hauth() != "" && r.Header.Get("Hauth") != s.Shop.Config.Get_Hauth(){
log.Println("Hauth header mismatch. Possible attempt to access shop from a possible forged request. ", r.RemoteAddr)
return
}
}

//Show Hauth for the specefied host
//tinfoil sends requests appending "/" at the end
if r.RequestURI == "/hauth/" && r.Header.Get("Hauth") != "" {
log.Println("HAUTH for ", s.Shop.Config.Host(), " is: ", headers["Hauth"])
return
}

//Root path checks
if r.RequestURI == "/" || utils.IsValidFilter(cleanPath(r.RequestURI)) {

// Check for blacklist/whitelist
Expand Down

0 comments on commit f8e405e

Please sign in to comment.