Skip to content

web: GET /target logs targets including GitHubToken to stdout, and continues after a datastore error #265

Description

@whywaita

Problem

handleTargetList (pkg/web/target.go:70-91) has two issues.

1. Installation token printed to stdout

ts, err := datastore.ListTargets(ctx, ds)
...
fmt.Println(ts)

fmt.Println(ts) (line 79) dumps the raw datastore.Target structs — including GitHubToken (a live GitHub Apps installation token) — to stdout on every GET /target request. The API response itself is properly sanitized via sanitizeTarget, but the debug print bypasses that. Any log aggregation collecting stdout stores valid tokens in plaintext (they expire after ~1h, but the window is real).

This looks like leftover debug code and should simply be removed.

2. Missing return after the error response

if err != nil {
    logger.Logf(false, "failed to retrieve list of target: %+v", err)
    outputErrorMsg(w, http.StatusInternalServerError, "datastore read error")
}
// execution continues: WriteHeader(200) is called again below

Lines 74-77: on a datastore error the handler writes a 500 but does not return, then falls through and writes a 200 header and body on the same response (http: superfluous response.WriteHeader + a bogus empty-list response to the client).

Suggested fix

  • Delete the fmt.Println(ts).
  • Add return after outputErrorMsg.
  • Consider changing GitHubToken to json:"-" in datastore.Target (pkg/datastore/interface.go) so an accidental direct serialization can never leak it structurally.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions