Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ioctl] fix log entries created from user input #3546

Merged
merged 3 commits into from
Jul 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions ioctl/cmd/contract/contractshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func share(args []string) error {
upload, err := os.ReadFile(_givenPath + "/" + getPayloadPath)
if err != nil {
log.Println("read file failed: ", err)
break
}
payload["content"] = string(upload)
payload["readonly"] = isReadOnly(_givenPath + "/" + getPayloadPath)
Expand All @@ -209,7 +210,7 @@ func share(args []string) error {
log.Println("send get response: ", err)
break
}
log.Println("share: " + _givenPath + "/" + getPayloadPath)
log.Printf("share: %s/%s\n", _givenPath, easpcapeString(getPayloadPath))

case "rename":
c := make(chan bool)
Expand All @@ -223,7 +224,7 @@ func share(args []string) error {
log.Println("send get response: ", err)
break
}
log.Println("rename: " + _givenPath + "/" + oldPath + " to " + _givenPath + "/" + newPath)
log.Printf("rename: %s/%s to %s/%s\n", _givenPath, easpcapeString(oldPath), _givenPath, easpcapeString(newPath))

case "set":
t := request.Payload
Expand All @@ -233,21 +234,26 @@ func share(args []string) error {
err := os.WriteFile(_givenPath+"/"+setPath, []byte(content), 0777)
if err != nil {
log.Println("set file failed: ", err)
break
}
if err := conn.WriteJSON(&response); err != nil {
log.Println("send set response: ", err)
break
}
log.Println("set: " + _givenPath + "/" + setPath)
log.Printf("set: %s/%s\n", _givenPath, easpcapeString(setPath))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is easpcapeString added here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user can make many new log entries, this is unsafe. https://github.com/iotexproject/iotex-core/security/code-scanning/10

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good. Could you reproduce this issue locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select branch in codeQL in actions. and run. see the result. this is mine https://github.com/iotexproject/iotex-core/security/code-scanning?query=is%3Aopen+branch%3Ahuof_fix_code_scan


default:
log.Println("Don't support this IDE yet. Can not handle websocket method: " + request.Key)
log.Printf("Don't support this IDE yet. Can not handle websocket method: %s\n", easpcapeString(request.Key))

}
}
})
log.Fatal(http.ListenAndServe(*_addr, nil))

return nil
}

func easpcapeString(str string) string {
escaped := strings.Replace(str, "\n", "", -1)
return strings.Replace(escaped, "\r", "", -1)
Comment on lines +280 to +281
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try `return strings.Replace(escaped, "[\r\n]", "", -1)

}