Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
github.com/aspose-words-cloud/aspose-words-cloud-go/v2101
/*
*/
package api_test
import ( "bufio" "bytes" "fmt" "io" "os" "path" "path/filepath" "regexp" "runtime" "testing"
"github.com/aspose-words-cloud/aspose-words-cloud-go/v2101/api"
"github.com/aspose-words-cloud/aspose-words-cloud-go/v2101/api/models"
)
func TestReadmeCode(t *testing.T) {
localFilePath := commonTestFile
remoteFolder := path.Join(remoteBaseTestDataFolder, "ReadmeCode")
remoteName := "ReadmeCode.docx"
remotePath := path.Join(remoteFolder, remoteName)
configFilePath := GetConfigFilePath()
// Start README example
// init words cloud api
config, _ := models.NewConfiguration(configFilePath)
wordsApi, ctx, _ := api.CreateWordsApi(config)
// upload test.docx to a cloud
// remote.docx is a name in the cloud
file, _ := os.Open(localFilePath)
uploadRequest := &models.UploadFileRequest{
FileContent: file,
Path: &remotePath,
}
wordsApi.UploadFile(ctx, uploadRequest)
// get a text for the first paragraph of the first section
options := map[string]interface{}{
"folder": remoteFolder,
}
request := &models.GetParagraphsRequest{
Name: &remoteName,
Optionals: options,
}
result, _, _ := wordsApi.GetParagraphs(ctx, request)
fmt.Println(result.Paragraphs.ParagraphLinkList[0].Text)
// End README example
writeToReadme(t)
}
func writeToReadme(t testing.T) { // set regexes startPatern := regexp.MustCompile("^\s// Start README example\s*$") endPattern := regexp.MustCompile("^\s*// End README example\s*$")
// set paths
_, filename, _, _ := runtime.Caller(0)
testFolder := filepath.Dir(filename)
sourcePath := filepath.Join(testFolder, "readme_test.go")
readmePath := filepath.Join(testFolder, "../../README.md")
// read the file
codeLines, err := readLines(sourcePath)
if err != nil {
t.Error(err)
}
// extract example code
var readmeCode []string
skipMode := true
for i := 0; i < len(codeLines); i++ {
if skipMode {
skipMode = !startPatern.Match([]byte(codeLines[i]))
}
if !skipMode {
readmeCode = append(readmeCode, codeLines[i])
skipMode = endPattern.Match([]byte(codeLines[i]))
}
}
if len(readmeCode) < 2 {
t.Error("Code has not found in readme_test.go")
}
// read readme.md
readmeLines, err := readLines(readmePath)
if err != nil {
t.Error(err)
}
// replace example code
var newReadmeLines []string
codeMode := false
for i := 0; i < len(readmeLines); i++ {
if !codeMode {
codeMode = startPatern.Match([]byte(readmeLines[i]))
if codeMode {
newReadmeLines = append(newReadmeLines, readmeCode...)
}
}
if codeMode {
codeMode = !endPattern.Match([]byte(readmeLines[i]))
continue
}
if !codeMode {
newReadmeLines = append(newReadmeLines, readmeLines[i])
}
}
// write new readme
err = writeLines(newReadmeLines, readmePath)
if err != nil {
t.Error(err)
}
}
// Read a whole file into the memory and store it as array of lines func readLines(path string) (lines []string, err error) { var ( file *os.File part []byte prefix bool ) if file, err = os.Open(path); err != nil { return } defer file.Close()
reader := bufio.NewReader(file)
buffer := bytes.NewBuffer(make([]byte, 0))
for {
if part, prefix, err = reader.ReadLine(); err != nil {
break
}
buffer.Write(part)
if !prefix {
lines = append(lines, buffer.String())
buffer.Reset()
}
}
if err == io.EOF {
err = nil
}
return
}
func writeLines(lines []string, path string) (err error) { var ( file *os.File )
if file, err = os.Create(path); err != nil {
return
}
defer file.Close()
for _, item := range lines {
_, err := file.WriteString(item + "\n")
if err != nil {
break
}
}
return
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.