Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Autenticación segura Go & Javascript

Actualmente estoy firmando usuarios (autenticando) desde el frontend y haciendo solicitudes al backend para registrar al usuario (guardar datos en la base de datos). Me doy cuenta de que no puedo evitar esto por completo, pero no quiero que se abuse de mi API (registro).

Vamos:

 func SignIn(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) u_ip := base64Decode((params["u_ip"])) u_wallet := base64Decode(string(params["u_wallet"])) u_password := base64Decode(params["u_pass"]) u_addr := strings.TrimPrefix(u_wallet, "0x") u_addr_temp := u_addr[0:7] for rowExists("select 1 from users where position(user_addr in $1)>0", u_addr_temp) { randInt := rand.Intn(5) u_addr_temp = u_addr[randInt : randInt+7] } sqlStatement := `INSERT INTO users (ip, user_addr, user_wallet, user_pass) VALUES($1, $2, $3, $4) returning id;` id := 0 db := opendb() err := db.QueryRow(sqlStatement, u_ip, u_addr_temp, u_wallet, u_password).Scan(&id) if err != nil { panic(err) } w.WriteHeader(http.StatusCreated) w.Header().Set("Content-Type", "application/json") resp := make(map[string]string) resp["message"] = string(id) + "-" + string(u_addr_temp) jsonResp, err := json.Marshal(resp) if err != nil { log.Fatalf("Json Err. Err: %s", err) } w.Write(jsonResp) }

JavaScript:

 const u_wallet = window.btoa(result); const u_password = window.btoa(password.toString()); await fetch( `http://localhost:8080/sign/${u_wallet}&${u_password}`, { method: "POST", } ) .then((response) => response.json()) .then((data) => console.log(data)); })();

Puede ver que los usuarios pueden llamar a http://localhost:8080/sign/${u_wallet}&${u_password} reemplazar la billetera y la contraseña (codificada en Base64) y GoLang creará automáticamente la fila (en la base de datos).

Ir CORS:

 c := cors.New(cors.Options{ AllowedOrigins: []string{"*"}, AllowCredentials: true, }) handler := c.Handler(router)

Puedo definir orígenes permitidos como origen estricto cuando origen cruzado, pero los usuarios usarán la consola de devtools (JS). Mi pregunta no es enviar los datos (de forma segura), sino cómo comunicarme desde el frontend y el backend, e intentar bloquear a los usuarios para que no llamen a la API.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!