Skip to content

demo: code-review bait (Go)#1

Open
kramlipi wants to merge 1 commit into
masterfrom
demo/code-review-bait
Open

demo: code-review bait (Go)#1
kramlipi wants to merge 1 commit into
masterfrom
demo/code-review-bait

Conversation

@kramlipi

Copy link
Copy Markdown
Owner

Summary

Demo PR for kramlipi code-agent code-review — intentional issues in demokramlipi/review_bait.go.

Notes

Do not merge. Showcase inline review comments.

— kramlipi · cluevion@gmail.com · https://kramlipi.com

Made with Cursor

@kramlipi kramlipi left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Automated code review by kramlip code-agent.

Review notes from kramlip code-agent — grounded scanners + critic, not a rubber stamp.

// BaitHandler has intentional issues for code-review demo.
func BaitHandler(w http.ResponseWriter, r *http.Request) {
var body []byte
n, _ := r.Body.Read(body) // ignore error; Read into nil slice

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Must fix · logic · demokramlipi/review_bait.go:11 · Unsafe read into nil slice

What: Reading into a nil slice results in 0 bytes read. Why it matters: The buffer remains empty, and the error return is ignored, masking potential I/O failures. Do this: Initialize the slice with a fixed size or use io.ReadAll.

fmt.Fprint(w, m["missing"])

s := r.URL.Query().Get("x")
fmt.Sprintf(s) // result discarded; format string from user

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Must fix · vulnerability · demokramlipi/review_bait.go:18 · Format string injection

What: Using user-controlled input as a format string in fmt.Sprintf. Why it matters: An attacker can provide malicious format specifiers (e.g., %s%s%s%s) to cause panics or leak memory. Do this: Use fmt.Print(s) or fmt.Printf("%s", s).

fmt.Fprintf(w, "n=%d data=%s", n, string(body))

var m map[string]string
fmt.Fprint(w, m["missing"])

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Should fix · design · demokramlipi/review_bait.go:15 · Fragile map access

What: Accessing a nil map is safe in Go (returns zero value), but relying on this behavior for business logic is brittle. Why it matters: It hides potential initialization bugs. Do this: Initialize the map or check for existence.

)

// BaitHandler has intentional issues for code-review demo.
func BaitHandler(w http.ResponseWriter, r *http.Request) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Worth a look · design · demokramlipi/review_bait.go:9 · No behavior risk: api_signature

What: No behavior risk: api_signature

Why it matters: The function signature follows standard http.HandlerFunc pattern.

Do this: Either fix it in this PR, or reply here explaining why the current behavior is intentional.

Evidence: func BaitHandler(w http.ResponseWriter, r *http.Request) {

// BaitHandler has intentional issues for code-review demo.
func BaitHandler(w http.ResponseWriter, r *http.Request) {
var body []byte
n, _ := r.Body.Read(body) // ignore error; Read into nil slice

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Worth a look · logic · demokramlipi/review_bait.go:11 · Possible ignored error

What: Error return may be ignored; check err before use.

Why it matters: (rule:unchecked_err_assign)

Do this: Either fix it in this PR, or reply here explaining why the current behavior is intentional.

Evidence: n, _ := r.Body.Read(body) // ignore error; Read into nil slice

@kramlipi

Copy link
Copy Markdown
Owner Author

Review notes

5 note(s) — 2 must-fix · 1 should-fix · 2 worth a look · 1 from deterministic scanners

Themes: logic (2), design (2), vulnerability (1)

Start here:

  • demokramlipi/review_bait.go:11 (must-fix) — Unsafe read into nil slice
  • demokramlipi/review_bait.go:18 (must-fix) — Format string injection
  • demokramlipi/review_bait.go:15 (should-fix) — Fragile map access
  • demokramlipi/review_bait.go:9 (look) — No behavior risk: api_signature
  • demokramlipi/review_bait.go:11 (look) — Possible ignored error

Review notes from kramlip code-agent — grounded scanners + critic, not a rubber stamp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant