Answer the question
In order to leave comments, you need to log in
Storing user-agent?
When a user is authorized, his user-agent is written to the database.
On average, a title is usually less than 200 characters, so varchar(200) is more than enough for it.
Suppose an attacker tries to break the system and sends a user-agent 1000 characters long.
The application handles this by simply storing the first 200 characters from the title.
Is this the right approach?
Where in such cases it is correct to store limits? Those. to set the sizes of the data in a DB in constants? in configs? Leave magic numbers?
I used such an approach that in the migrations for the database, the constants specified in the code were used, and the validators were attached to the same constants. How correct is this?
Almost pseudocode
migration.php
use Constants;
class Migration {
public function run() {
$this->db->addColumn('table', 'column', Constants::USER_AGENT_LENGTH);
}
}
Controller.php
use Constants;
class Controller {
public function login(Request $request) {
$userAgent = substr($request->header('user-agent'), 0, Constants::USER_AGENT_LENGTH);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question