简体   繁体   English

如何在 Java 代码中使用 Fortify 注释?

[英]How do I use Fortify Annotations In Java Code?

I have a question regarding the names and syntax for using Fortify Code Annotations.我对使用 Fortify 代码注释的名称和语法有疑问。

The short, short, really short version is: I am looking for a guide/manual that will list the available in-code annotations and provide an example for their intended use.简短,简短,非常简短的版本是:我正在寻找一份指南/手册,其中将列出可用的代码内注释并提供其预期用途的示例。 Specifically for use in having a set of "SQL Injection" and "SQL Injection: Persistence" issues omitted from Fortify Scan results.专门用于从 Fortify 扫描结果中省略一组“SQL 注入”和“SQL 注入:持久性”问题。

TL;DR; TL;博士; Details:细节:

  • Fortify Version: 19.1.0强化版本:19.1.0
  • Platform: Java 8;平台:Java 8; Web App (Weblogic 12.2.1.4.0 (12c)); Web 应用程序(Weblogic 12.2.1.4.0 (12c)); Redhat Unix红帽 Unix
  • Fortify Issue: SQL Injection (WASC-19)强化问题:SQL 注入 (WASC-19)
  • Additional Information: The code exists as part of a web application.附加信息:代码作为 web 应用程序的一部分存在。

The "suspect" input String arrives from the client and then becomes part of a DDL Statement ("ALTER SESSION...") This "cannot be changed" and DDL statements cannot be parameterized . “可疑”输入字符串从客户端到达,然后成为 DDL 语句的一部分(“ALTER SESSION...”)这个“无法更改”且DDL 语句无法参数化

Sanitizing the input String is ridiculously easy.清理输入字符串非常容易。 The (7 character) String is fed through a Regex parser: Pattern.compile(HARDCODED_REGEX_CONSTANT).matcher(suspectString); (7 个字符)字符串通过正则表达式解析器提供: Pattern.compile(HARDCODED_REGEX_CONSTANT).matcher(suspectString);

Using an annotated method declaration that sends the input though a regex parser has also been part of the validation eg @Pattern(regexp=HARDCODED_REGEX_CONSTANT)使用通过正则表达式解析器发送输入的带注释的方法声明也是验证的一部分,例如@Pattern(regexp=HARDCODED_REGEX_CONSTANT)

Neither of these 2 approaches are sufficient for Fortify.这两种方法都不足以 Fortify。

Additionally, the suspect input String is also validated against known and valid values (the values are pulled from the database, so Fortify also finds that those values are also "suspect").此外,可疑输入字符串还会根据已知和有效值进行验证(这些值是从数据库中提取的,因此 Fortify 还发现这些值也是“可疑的”)。

Of course, none of these are satisfactory for the Fortify Scan.当然,这些都不能满足 Fortify Scan 的要求。

Creating and storing a custom rule that is external to the code and applied to the scan results is "not going to work" because of "reasons" .由于“原因” ,创建和存储代码外部并应用于扫描结果的自定义规则“不起作用”。 [I cannot adequately or briefly explain why this simple solution has been rejected.] Suffice it to say, creating a set of "False Positives" to import prior to a Fortify Scan; [我无法充分或简要地解释为什么这个简单的解决方案被拒绝了。] 可以这么说,在 Fortify 扫描之前创建一组“误报”来导入; is "not an option" nor is marking "known issues" as "Not an Issue".“不是一个选项” ,也不是将“已知问题”标记为“不是问题”。

Placing an "Ignore this" comment in the code does not satisfy the goal state either.在代码中放置“忽略此”注释也不满足目标 state。 The end evaluation is that the issue remains in the scan results, it is critical, and therefore MUST be resolved.最终评估是问题仍然存在于扫描结果中,它很关键,因此必须解决。

Restating the request: I would like to place an annotation (or other in-code construct) (eg @FortifyValidate , @Fortify????? , etc.) at the points at which a problem is flagged by the Fortify scan.重申请求:我想在 Fortify 扫描标记问题的点放置注释(或其他代码内构造)(例如@FortifyValidate@Fortify?????等)。

I cannot find an adequate guide/manual online that will list the available in-code annotations and provide an example for their intended use.我找不到足够的在线指南/手册来列出可用的代码内注释并为其预期用途提供示例。 Specifically for use in having a set of "SQL Injection" and "SQL Injection: Persistence" issues omitted from Fortify Scan results.专门用于从 Fortify 扫描结果中省略一组“SQL 注入”和“SQL 注入:持久性”问题。

Thank you谢谢

Answering my own question as best I can.尽我所能回答我自己的问题。

The answer that I arrived at was the use of Fortify Annotations.我得到的答案是使用 Fortify Annotations。 This is not, however, the preferred means by which Fortify issues "should be" resolved.然而,这不是“应该”解决 Fortify 问题的首选方法。 The preferred means of identification, mitigation, and resolution is through the Audit Workbench and Fortify Software Security Center that is integrated into supported Testing and QA processes.识别、缓解和解决的首选方法是通过集成到受支持的测试和 QA 流程中的 Audit Workbench 和 Fortify 软件安全中心。 Micro Focus provides an overview of how this process can be modeled. Micro Focus 概述了如何对该过程进行建模。 https://www.microfocus.com/documentation/fortify-static-code-analyzer-and-tools/1810/AWB_Guide_18.10.pdf https://www.microfocus.com/documentation/fortify-static-code-analyzer-and-tools/1810/AWB_Guide_18.10.pdf

That type of development environment is not available to me.我无法使用那种类型的开发环境。

So, on to the hack:所以,关于黑客:

The only documentation that I found online was: https://community.microfocus.com/t5/Fortify-User-Discussions/Using-Fortify-Java-Annotations/td-p/1500577 It has a few misspellings, but is accurate and useful for integrating the Fortify Annotations library into an existing maven project and then placing the annotations into the code.我在网上找到的唯一文档是: https://community.microfocus.com/t5/Fortify-User-Discussions/Using-Fortify-Java-Annotations/td-p/1500577它有一些拼写错误,但准确且用于将 Fortify Annotations 库集成到现有 maven 项目中,然后将注释放入代码中。

Items of note: The page is from 2014 and the Fortify version that is referenced is 4.00.注意事项:该页面来自 2014 年,引用的 Fortify 版本是 4.00。 Make sure to use your current Fortify version.确保使用您当前的 Fortify 版本。 Secondly, there are 2 jar files in Fortify 19.1.0 that contain the annotation definitions.其次,在 Fortify 19.1.0 中有 2 个 jar 文件包含注释定义。 They are FortifyAnnotations-CLASS.jar and FortifyAnnotations-SOURCE.jar .它们是FortifyAnnotations-CLASS.jarFortifyAnnotations-SOURCE.jar I chose to rename the -CLASS.jar and use it instead of cluttering up the build process.我选择重命名-CLASS.jar并使用它而不是弄乱构建过程。

Once imported, or added to the classpath;导入或添加到类路径后; it is a simple matter to use the annotations to remove specific "taints" @FortifyXSSValidate or generalized blanket validation @FortifyValidate .使用注释来删除特定的“污点” @FortifyXSSValidate或通用的一揽子验证@FortifyValidate是一件简单的事情。

When custom code is used to ensure validity, it is very useful to use @FortifyValidate("return") annotations.当使用自定义代码来确保有效性时,使用@FortifyValidate("return")注解非常有用。

I recommend using an annotation that is as concise as possible for preventing Fortify from flagging mitigated issues.我建议使用尽可能简洁的注释来防止 Fortify 标记缓解的问题。 I would also recommend placing some inline notes or documentation that thoroughly describes why an Annotation has been placed and exactly what makes its placement a viable solution.我还建议放置一些内联注释或文档,这些注释或文档彻底描述了为什么放置 Annotation 以及究竟是什么使它的放置成为可行的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM