@@ -59,6 +59,7 @@ import (
5959 "github.com/tikv/pd/server/keyspace"
6060 "github.com/tikv/pd/server/member"
6161 syncer "github.com/tikv/pd/server/region_syncer"
62+ "github.com/tikv/pd/server/replication"
6263 "github.com/tikv/pd/server/schedule"
6364 "github.com/tikv/pd/server/schedule/hbstream"
6465 "github.com/tikv/pd/server/schedule/placement"
@@ -1678,8 +1679,15 @@ func (s *Server) ReplicateFileToMember(ctx context.Context, member *pdpb.Member,
16781679
16791680// PersistFile saves a file in DataDir.
16801681func (s * Server ) PersistFile (name string , data []byte ) error {
1682+ if name != replication .DrStatusFile {
1683+ return errors .New ("Invalid file name" )
1684+ }
16811685 log .Info ("persist file" , zap .String ("name" , name ), zap .Binary ("data" , data ))
1682- return os .WriteFile (filepath .Join (s .GetConfig ().DataDir , name ), data , 0644 ) // #nosec
1686+ path := filepath .Join (s .GetConfig ().DataDir , name )
1687+ if ! isPathInDirectory (path , s .GetConfig ().DataDir ) {
1688+ return errors .New ("Invalid file path" )
1689+ }
1690+ return os .WriteFile (path , data , 0644 ) // #nosec
16831691}
16841692
16851693// SaveTTLConfig save ttl config
0 commit comments