diff --git a/docs/diagnostics/InternetAccess.md b/docs/diagnostics/InternetAccess.md new file mode 100644 index 00000000000..974639618c7 --- /dev/null +++ b/docs/diagnostics/InternetAccess.md @@ -0,0 +1,21 @@ +# Обращение к Интернет-ресурсам (InternetAccess) + + +## Описание диагностики + +Проверьте обращение к Интернет-ресурсам и набор передаваемых данных для исключения передачи конфиденциальной или защищенной информации. + +## Примеры + +```bsl +HTTPСоединение = Новый HTTPСоединение("zabbix.localhost", 80); // замечание +FTPСоединение = Новый FTPСоединение(Сервер, Порт, Пользователь, Пароль); // замечание +``` + +## Источники + + diff --git a/docs/en/diagnostics/InternetAccess.md b/docs/en/diagnostics/InternetAccess.md new file mode 100644 index 00000000000..9c2305abc49 --- /dev/null +++ b/docs/en/diagnostics/InternetAccess.md @@ -0,0 +1,16 @@ +# Referring to Internet resources (InternetAccess) + + +## Description + + +## Examples + + +## Sources + + diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnostic.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnostic.java new file mode 100644 index 00000000000..cb5c0017b64 --- /dev/null +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnostic.java @@ -0,0 +1,61 @@ +/* + * This file is a part of BSL Language Server. + * + * Copyright (c) 2018-2024 + * Alexey Sosnoviy , Nikita Fedkin and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * BSL Language Server is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * BSL Language Server is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with BSL Language Server. + */ +package com.github._1c_syntax.bsl.languageserver.diagnostics; + +import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata; +import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity; +import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticTag; +import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType; +import com.github._1c_syntax.bsl.languageserver.utils.bsl.Constructors; +import com.github._1c_syntax.bsl.parser.BSLParser; +import com.github._1c_syntax.utils.CaseInsensitivePattern; +import org.antlr.v4.runtime.tree.ParseTree; + +import java.util.regex.Pattern; + +@DiagnosticMetadata( + type = DiagnosticType.VULNERABILITY, + severity = DiagnosticSeverity.MAJOR, + minutesToFix = 60, + tags = { + DiagnosticTag.SUSPICIOUS + }, + activatedByDefault = false +) + +public class InternetAccessDiagnostic extends AbstractVisitorDiagnostic { + private static final Pattern PATTERN_NEW_EXPRESSION = CaseInsensitivePattern.compile( + "FTPСоединение|FTPConnection|HTTPСоединение|HTTPConnection|WSОпределения|WSDefinitions|WSПрокси|WSProxy" + + "|ИнтернетПочтовыйПрофиль|InternetMailProfile|ИнтернетПочта|InternetMail|Почта|Mail|HTTPЗапрос|HTTPRequest|" + + "ИнтернетПрокси|InternetProxy"); + + @Override + public ParseTree visitNewExpression(BSLParser.NewExpressionContext ctx) { + Constructors.typeName(ctx).ifPresent((String typeName) -> { + var matcherTypeName = PATTERN_NEW_EXPRESSION.matcher(typeName); + if (matcherTypeName.matches()) { + diagnosticStorage.addDiagnostic(ctx); + } + }); + return super.visitNewExpression(ctx); + } +} diff --git a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json index ccdeecf2665..13ab035dbca 100644 --- a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json +++ b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json @@ -962,6 +962,16 @@ "title": "Incorrect use of \"StrTemplate\"", "$id": "#/definitions/IncorrectUseOfStrTemplate" }, + "InternetAccess": { + "description": "Referring to Internet resources", + "default": false, + "type": [ + "boolean", + "object" + ], + "title": "Referring to Internet resources", + "$id": "#/definitions/InternetAccess" + }, "InvalidCharacterInFile": { "description": "Invalid character", "default": true, diff --git a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnostic_en.properties b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnostic_en.properties new file mode 100644 index 00000000000..1e4019e3eb8 --- /dev/null +++ b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnostic_en.properties @@ -0,0 +1,2 @@ +diagnosticMessage=Check the reference to Internet resources +diagnosticName=Referring to Internet resources diff --git a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnostic_ru.properties b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnostic_ru.properties new file mode 100644 index 00000000000..4cf26b98770 --- /dev/null +++ b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnostic_ru.properties @@ -0,0 +1,2 @@ +diagnosticMessage=Проверьте обращение к Интернет-ресурсам +diagnosticName=Обращение к Интернет-ресурсам diff --git a/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnosticTest.java b/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnosticTest.java new file mode 100644 index 00000000000..2b6216a8a47 --- /dev/null +++ b/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/InternetAccessDiagnosticTest.java @@ -0,0 +1,57 @@ +/* + * This file is a part of BSL Language Server. + * + * Copyright (c) 2018-2024 + * Alexey Sosnoviy , Nikita Fedkin and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * BSL Language Server is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * BSL Language Server is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with BSL Language Server. + */ +package com.github._1c_syntax.bsl.languageserver.diagnostics; + +import org.eclipse.lsp4j.Diagnostic; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static com.github._1c_syntax.bsl.languageserver.util.Assertions.assertThat; + +class InternetAccessDiagnosticTest extends AbstractDiagnosticTest { + InternetAccessDiagnosticTest() { + super(InternetAccessDiagnostic.class); + } + + @Test + void test() { + + List diagnostics = getDiagnostics(); + + assertThat(diagnostics, true) + .hasRange(1, 20, 75) + .hasRange(3, 18, 72) + .hasRange(5, 16, 80) + .hasRange(8, 8, 111) + .hasRange(13, 21, 65) + .hasRange(14, 17, 35) + .hasRange(15, 17, 47) + .hasRange(16, 17, 43) + .hasRange(17, 21, 51) + .hasRange(21, 14, 43) + .hasRange(27, 14, 32) + .hasRange(31, 14, 35) + .hasRange(34, 10, 21) + .hasSize(13); + } +} diff --git a/src/test/resources/diagnostics/InternetAccessDiagnostic.bsl b/src/test/resources/diagnostics/InternetAccessDiagnostic.bsl new file mode 100644 index 00000000000..f556f167b3a --- /dev/null +++ b/src/test/resources/diagnostics/InternetAccessDiagnostic.bsl @@ -0,0 +1,35 @@ +Процедура Тест1() + FTPСоединение = Новый FTPСоединение(Сервер, Порт, Пользователь, Пароль); // ошибка + + Определения = Новый WSОпределения("http://localhost/test.asmx?WSDL"); // ошибка + + ПроксиДва = Новый WSПрокси(Определения, "http://localhost/", "test", "test"); // ошибка + + Определения = + Новый WSОпределения("http://localhost/test.asmx?WSDL", "Пользователь", "Пароль", Неопределено, Таймаут); // ошибка + +КонецПроцедуры + +Процедура HTTP() + HTTPСоединение = Новый HTTPСоединение("zabbix.localhost", 80); // ошибка + HTTPЗапрос = Новый HTTPЗапрос(); // ошибка + HTTPЗапрос = Новый HTTPЗапрос("zabbix", 80); // ошибка + HTTPЗапрос = Новый HTTPЗапрос("zabbix"); // ошибка + ИнтернетПрокси = Новый ИнтернетПрокси("zabbix"); // ошибка +КонецПроцедуры + +Функция НовыйИнтернетПочтовыйПрофильБезТаймАута() + Профиль = Новый ИнтернетПочтовыйПрофиль; // ошибка + Профиль.Пользователь = "admin"; + Возврат Профиль; +КонецФункции + +Функция InternetMail() + Профиль = Новый InternetMail; // ошибка +КонецФункции + +Функция InternetMail_НовыйИмя() + Профиль = Новый("InternetMail"); // ошибка +КонецФункции + +Профиль = Новый Почта; // ошибка