C# Linq to SQL 包含安全的 sql 注入

如何解决C# Linq to SQL 包含安全的 sql 注入

通常我知道 Linq to SQL 对于 SQL 注入是安全的,因为它使用 be8ec4e48d7f: Already exists 33b8b485aff0: Already exists d887158cc58c: Already exists 05895bb28c18: Already exists 3717254b824f: Already exists 5d1752e32f1f: Already exists 98554cf2e2ec: Already exists 3a83ccd2f4ee: Already exists c793dcd65f37: Already exists c4412ad3121f: Already exists eba3bc56bff9: Already exists 2b1b6e815dce: Already exists dda735bf3557: Already exists dbece9223ffc: Already exists 49533680b25f: Already exists 8d332721c923: Already exists d40c3e8ecbdb: Already exists 75f43ec617dd: Already exists 225f75c25e6b: Already exists 81811c4b9e22: Already exists 409197acab0f: Already exists 9b5199518afc: Already exists b7040ab58553: Already exists b6e55490ca80: Already exists e04c7210075d: Already exists 68db66ab7dda: Already exists bbe68713195e: Already exists 1d7c9599b03c: Already exists c7472ba4bdbd: Already exists 3c4082628c2e: Already exists 50f7a489c209: Already exists aaf98f685aa2: Already exists 8cf31fcd419c: Already exists a80092fe6016: Already exists 9d90bdef5603: Already exists 9d13d2b62b19: Already exists cab2bcedcfdf: Already exists 41670cbb355b: Already exists 4036f94db6f4: Retrying in 19 seconds 42f95b51f0f7: Download complete 91f3ac158888: Download complete df09d420f619: Download complete 7ca46f747969: Download complete 34e5e5eb8b2f: Download complete ce8b1ad11171: Download complete 4b124d6694bd: Download complete a71b50d0f70c: Download complete 237b8823183b: Download complete 4036f94db6f4: Downloading 12.41MB/12.41MB 64858da6aaea: Download complete 3e88dcb59e3e: Download complete aa92021cb41d: Download complete 0569c05fcc65: Download complete 63ee9c05e34b: Download complete 48ac0999fcdb: Download complete e10d1975849c: Download complete 611db2146c6f: Download complete 7ad4e600c6c6: Download complete 4261ad6f88e3: Download complete c20e2f82fd11: Download complete 49f62c0b1913: Download complete cb37060da14d: Download complete f19eda2c4fb2: Download complete e600fca97576: Download complete 508947b05054: Download complete 652c4860c2f3: Download complete 358d27eb7aaa: Download complete 27cfd1cb1501: Download complete 673d626b28c0: Download complete 20d0b16ebf52: Download complete 0cfff8a600f6: Download complete 00065e08cdfc: Download complete bd51e67b9159: Download complete 7e8e6548bdec: Download complete 1dea31859db5: Download complete f058efbc49a4: Download complete 3e10bb0abdd8: Download complete 617d42f04950: Download complete 798390048c18: Download complete 2b389764a032: Download complete 002f5c6ccc90: Download complete unexpected EOF (如 herehere 所述)。

但是 SqlParameter 的情况如何:

contains

如果我直接在 SQL Server 中记录查询,我可以看到使用了以下查询:

StreetRepository.Streets.Where(w => w.Streetname.Contains("Road"))

正如我们所见,该查询没有使用参数。如果我使用以下命令:

SELECT [Extent1].[Id] AS [Id],[Extent1].[Streetname] AS [Streetname] 
FROM [dbo].[Streets] AS [Extent1]  
WHERE [Extent1].[Streetname] LIKE N'%Road%'

我明白了:

StreetRepository.Streets.Where(w => w.Streetname.Contains("Road' OR 1=1"))

在这种情况下,它由双 SELECT [Extent1].[Id] AS [Id],[Extent1].[Streetname] AS [Streetname] FROM [dbo].[Streets] AS [Extent1] WHERE [Extent1].[Streetname] LIKE N'%Road'' OR 1=1%' 转义。

但这对所有攻击都足够安全吗?我可以放心使用 contains 吗?如果不是,我可以用什么代替 ''

解决方法

参数不仅仅是防止 SQL 注入的方法。 LINQ to SQL 知道如何正确转义字符串。所以别担心,一切都会好的。

无论如何,如果您更喜欢参数,只需将字符串值放入局部变量即可:

var streetName = "Road";
StreetRepository.Streets.Where(w => w.Streetname.Contains(streetName));

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-