Delete by id is not enough - an ownership check in a Uniface form
The customer app from the series Building a customer app in Uniface 10 has had a note service for a long time. Stage 28 gave it a form: choose a customer, see the notes, add one, delete one. Tested with Rocket Uniface 1
The customer app from the series Building a customer app in Uniface 10 has had a note service for a long time. Stage 28 gave it a form: choose a customer, see the notes, add one, delete one.
Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, October 2026. The app uses SQLite through the SLE driver (SQLite 3.50.2).
The service deletes what it is told
public operation DELETE_NOTE
params
numeric pNoteId : IN
string pError : OUT
endparams
pError = ""
activate "RIGHTS_SVC".REQUIRE("EDIT", pError)
if ($status < 0)
return -1
endif
sql "DELETE FROM CUSTOMER_NOTE WHERE NOTE_ID = %%(pNoteId)", "CUSTOMERS"
if ($status < 0)
pError = $concat("The note could not be deleted (error ", $procerror, ").")
return -1
endif
return 0
end
The service checks the role (EDIT) and deletes the row with that id. It does not know which customer the form shows, and it does not report whether a row was deleted at all.
In the form, the note id is a field the user types into. A typo, or an id copied from another customer's list, would delete a note the user does not see.
The form checks against the list it shows
Before the question "Delete note N?" the form loads the notes of the current customer through the same service operation it uses for the list, and looks for the id:
entry DO_DELETE
variables
string vError, vData, vRow, vId
boolean vFound
endvariables
call NEED_CUST
if ($status < 0)
return -1
endif
if (N_ID.NTS_DMY = "")
INFO.NTS_DMY = "Please enter a note id."
return -1
endif
activate "NOTE_SVC".LOAD_FOR_CUSTOMER($cCust$, vData, vError)
if ($status < 0)
INFO.NTS_DMY = vError
return -1
endif
vFound = 0
forlist vRow in vData
getitem vId, vRow, 1
if (vId = N_ID.NTS_DMY)
vFound = 1
endif
endfor
if (vFound = 0)
INFO.NTS_DMY = "Note %%(N_ID.NTS_DMY) does not belong to this customer."
return -1
endif
askmess/question "Delete note %%(N_ID.NTS_DMY)?~Delete note", "Yes,No"
if ($status != 1)
return 0
endif
activate "NOTE_SVC".DELETE_NOTE(N_ID.NTS_DMY, vError)
if ($status < 0)
rollback
INFO.NTS_DMY = vError
return -1
endif
commit
call DO_LIST
INFO.NTS_DMY = "Note %%(N_ID.NTS_DMY) deleted."
N_ID.NTS_DMY = ""
return 0
end
Only if the id is in that list does the form ask, delete and commit. The check uses the service again instead of a separate SQL statement in the form, so the form does not need to know the table.
Click test
Test data: two customers, two notes for the first one.
- Customer 2 loaded, note id 1 entered, "Delete note...": "Note 1 does not belong to this customer." No question, nothing deleted.
- Customer 1 loaded, note id 1, "Delete note...", answer Yes: "Note 1 deleted." The list shows one note left.
- "Add note" with an empty text: "Please enter a note text." (message from the service).
- A user with role READ sees the buttons for adding and deleting dimmed.
Notes
- A service operation that takes only an id is fine for callers that already know the id is valid. A form with a free id field is not such a caller.
- The check belongs where the context is: the form knows which customer is on the screen, the service does not.
- Reusing the list operation keeps the check consistent with what the user sees.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.