假设您有一个如下所示的查询:
SELECT * FROM messages WHERE sender='clean_username'
Run Code Online (Sandbox Code Playgroud)
clean_username收到/收到的地方,并像这样清理:
$clean_username = preg_replace( '/[^A-Za-z0-9_]+/m' , '', $dirty_username );
Run Code Online (Sandbox Code Playgroud)
上面的代码删除了任何空格(以及其他内容),这意味着valid_username参数将始终只是一个单词.
注射可以利用这种方法最简单的方法是什么?
我问这个问题是为了更好地理解SQL注入的工作原理.在我的工作中,我坚持使用准备好的语句和参数化查询以防止注入的既定良好实践,但我认为人们也应该了解如何在这样的简单场景中注入恶意代码.
我每隔1.5分钟就用我的C#app执行一次Google应用程序脚本.应用脚本在电子表格和编辑表单之间移动内容.我也使用Drive API.
我的脚本长时间运行良好,除了我每小时收到5分钟的授权错误.
这是我处理授权的代码:
class Authentication
{
public static ScriptService ScriptsAuthenticateOauth(UserCredential credential)
{
try
{
ScriptService service = new ScriptService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "MyApp",
});
return service;
}
catch (Exception ex)
{
Console.WriteLine(DateTime.Now.ToString("HH:mm") + ": An authentication error occurred: " + ex.InnerException);
return null;
}
}
public static UserCredential getCredential(string clientId, string clientSecret, string userName)
{
string[] scopes = new string[] { DriveService.Scope.Drive, // view and manage your files and documents
DriveService.Scope.DriveAppdata, // view and manage …Run Code Online (Sandbox Code Playgroud) 给定一个像这样的表:
CREATE TABLE the_table (
the_uuid UUID NOT NULL UNIQUE DEFAULT gen_random_uuid()
-- more columns
);
Run Code Online (Sandbox Code Playgroud)
如果我们插入没有列值的行the_uuid,并且 DBMS 生成随机 UUID,postgres 是否可以无缝处理生成列中已存在的 UUID 的不太可能的情况?
人们会想象 postgres 可以重试随机 UUID 生成,直到它获得不违反约束的 UUID。但如果 postgres 不是以这种方式实现的,则需要在外部处理这个问题。
对于数字类型,我们有 a 的想法SEQUENCE可以在一定程度上解决这个问题,但我不知道该类型的类似物UUID。
这个问题的许多读者会想评论或回答说我担心一些不太可能发生的事情,我同意,但我仍然有兴趣更好地理解 postgres 处理这个问题的方式。