-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ETQ tech: je veux publier les fichiers opendata selon les bonnes pratiques de data.gouv #11100
base: main
Are you sure you want to change the base?
Conversation
|
||
def existing_data(dataset, resource) | ||
file_url = APIDatagouv::API.get_existing_file_url(dataset, resource) | ||
csv_data = URI.open(file_url).read |
Check failure
Code scanning / CodeQL
Use of `Kernel.open` or `IO.read` or similar sinks with a non-constant value Critical
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 8 hours ago
To fix the problem, we should replace the use of URI.open
with a safer alternative. Specifically, we can use Net::HTTP.get
to fetch the content of the URL, which does not have the same vulnerability as URI.open
.
- Replace the call to
URI.open(file_url).read
withNet::HTTP.get(URI.parse(file_url))
. - Ensure that the
net/http
library is required at the top of the file if it is not already.
-
Copy modified line R2 -
Copy modified line R48
@@ -1,2 +1,3 @@ | ||
# frozen_string_literal: true | ||
require 'net/http' | ||
|
||
@@ -46,3 +47,3 @@ | ||
file_url = APIDatagouv::API.get_existing_file_url(dataset, resource) | ||
csv_data = URI.open(file_url).read | ||
csv_data = Net::HTTP.get(URI.parse(file_url)) | ||
data = [] |
|
||
def existing_data(dataset, resource) | ||
file_url = APIDatagouv::API.get_existing_file_url(dataset, resource) | ||
csv_data = URI.open(file_url).read |
Check failure
Code scanning / CodeQL
Use of `Kernel.open`, `IO.read` or similar sinks with user-controlled input Critical
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 8 hours ago
To fix the problem, we need to replace the URI.open
call with a safer alternative. The recommended approach is to use URI(<uri>).open
or an HTTP client to fetch the content. This ensures that the URL is properly parsed and validated before being used.
In this case, we will replace URI.open(file_url).read
with URI(file_url).open.read
. This change will ensure that the URL is parsed and validated before being opened, mitigating the risk of injection attacks.
-
Copy modified line R47
@@ -46,3 +46,3 @@ | ||
file_url = APIDatagouv::API.get_existing_file_url(dataset, resource) | ||
csv_data = URI.open(file_url).read | ||
csv_data = URI(file_url).open.read | ||
data = [] |
|
||
def existing_data(dataset, resource) | ||
file_url = APIDatagouv::API.get_existing_file_url(dataset, resource) | ||
csv_data = URI.open(file_url).read |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 8 hours ago
To fix the problem, we need to ensure that the URL derived from the HTTP response is validated before it is used. One way to do this is to check that the URL belongs to a trusted domain. This can be done by parsing the URL and verifying its host against a whitelist of allowed hosts.
- Parse the URL using
URI.parse
. - Check that the host of the URL is in a predefined list of allowed hosts.
- Raise an error or handle the case where the URL is not from an allowed host.
-
Copy modified line R2 -
Copy modified lines R48-R52
@@ -1,2 +1,3 @@ | ||
# frozen_string_literal: true | ||
require 'uri' | ||
|
||
@@ -46,2 +47,7 @@ | ||
file_url = APIDatagouv::API.get_existing_file_url(dataset, resource) | ||
uri = URI.parse(file_url) | ||
allowed_hosts = ["trusted.domain.com"] | ||
unless allowed_hosts.include?(uri.host) | ||
raise "Untrusted URL host: #{uri.host}" | ||
end | ||
csv_data = URI.open(file_url).read |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11100 +/- ##
===========================================
- Coverage 84.35% 44.61% -39.75%
===========================================
Files 1176 1178 +2
Lines 25944 30847 +4903
Branches 4898 3953 -945
===========================================
- Hits 21886 13762 -8124
- Misses 4058 17085 +13027 ☔ View full report in Codecov by Sentry. |
Dans le dataset "utilisation de DS" : https://www.data.gouv.fr/fr/datasets/utilisation-du-service-demarches-simplifiees/
Aujourd'hui, on ajoute chaque mois une nouvelle resource par type de données :
Ceci ne suit pas les bonnes pratiques de data.gouv pour faciliter la réutilisation.
Il est préférable de maintenir à jour, chaque mois, une même resource par type de données. Cela revient à ajouter de nouvelles lignes aux mêmes fichiers.
PR en draft, cas d'usage sur "Nombre de comptes créés par mois"