Skip to content

Use opengribs.org API#111

Closed
svenseeberg wants to merge 1 commit into
mainfrom
feature/opengribs
Closed

Use opengribs.org API#111
svenseeberg wants to merge 1 commit into
mainfrom
feature/opengribs

Conversation

@svenseeberg
Copy link
Copy Markdown
Member

@svenseeberg svenseeberg commented Oct 4, 2025

Use opengribs.org to fetch sea currents and wind data. We first have to request a GRIBS file via the API. The API then returns a download path after a few seconds. The file is downloaded into the simulation input directory and should automatically be used.

Fix #74

@svenseeberg svenseeberg force-pushed the feature/opengribs branch 5 times, most recently from d9cc2b4 to a95a59f Compare October 4, 2025 10:03
Comment thread opendrift_leeway_webgui/leeway/utils.py Fixed
Comment thread opendrift_leeway_webgui/leeway/utils.py Fixed
@svenseeberg svenseeberg force-pushed the feature/opengribs branch 4 times, most recently from 7c6923d to a28aac7 Compare October 4, 2025 10:58
"""
bbox = create_opengribs_bounding_box(longitude, latitude)
download_url = request_opengribs_file(bbox)
logger.info(f"Got GRIBS file {download_url} for {bbox}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.

Copilot Autofix

AI 5 months ago

In general, to fix clear-text logging of sensitive data, remove sensitive fields from log messages or replace them with non-sensitive summaries (e.g., IDs, coarse buckets, or hashes) while preserving enough context for debugging. When you need to trace operations without exposing raw values, log an opaque identifier or a redacted/rounded representation instead of exact data.

For this specific issue, the problem is that logger.info(f"Got GRIBS file {download_url} for {bbox}") logs a bounding box derived from sensitive coordinates. The simplest fix that preserves behavior is to stop logging bbox entirely or replace it with a non-sensitive placeholder. Since download_url is already sufficient to understand what has been retrieved operationally, we can modify the log line to only mention the URL, or, if more context is needed, log the filename derived from the URL. No changes are required to how the data is requested or processed; only the log message string needs adjustment.

Concretely, in opendrift_leeway_webgui/leeway/utils.py at line 305, change the log call to avoid embedding the bbox dict (and thus latitude/longitude-derived values). For example:

logger.info("Got GRIBS file %s", download_url)

or, if you want slightly more context without coordinates:

logger.info("Got GRIBS file for OpenGRIBS request: %s", download_url)

This requires no new imports or helper methods, and it addresses all alert variants since every tainted path flows into bbox in that single log call.

Suggested changeset 1
opendrift_leeway_webgui/leeway/utils.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/opendrift_leeway_webgui/leeway/utils.py b/opendrift_leeway_webgui/leeway/utils.py
--- a/opendrift_leeway_webgui/leeway/utils.py
+++ b/opendrift_leeway_webgui/leeway/utils.py
@@ -302,5 +302,5 @@
     """
     bbox = create_opengribs_bounding_box(longitude, latitude)
     download_url = request_opengribs_file(bbox)
-    logger.info(f"Got GRIBS file {download_url} for {bbox}")
+    logger.info("Got GRIBS file %s", download_url)
     return get_opengribs_file(download_url)
EOF
@@ -302,5 +302,5 @@
"""
bbox = create_opengribs_bounding_box(longitude, latitude)
download_url = request_opengribs_file(bbox)
logger.info(f"Got GRIBS file {download_url} for {bbox}")
logger.info("Got GRIBS file %s", download_url)
return get_opengribs_file(download_url)
Copilot is powered by AI and may make mistakes. Always verify output.
str(simulation.uuid),
"--no-web",
]
print(" ".join(params))

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.

Copilot Autofix

AI 5 months ago

In general, to fix clear‑text logging of sensitive data you should avoid logging raw user-derived values or full command lines containing such values. Either remove the log, reduce it to non-sensitive, high-level information, or explicitly redact the sensitive fields before logging.

For this specific case, the minimal, non‑functional change is to stop printing the full docker command string containing simulation.longitude and simulation.latitude. Since this is a Celery task that already uses a logger, the best fix is to replace the print(" ".join(params)) with a safer debug message that omits or redacts sensitive parameters while still giving some context (e.g., logging only the simulation UUID or that a simulation is starting). This avoids introducing new behavior while retaining observability. No other parts of the snippet require changes, and no new imports or helper methods are needed.

Concretely:

  • In opendrift_leeway_webgui/leeway/tasks.py, at line 56, replace print(" ".join(params)) with a logger.debug call that does not include longitude/latitude or any other sensitive data. For example: logger.debug("Starting leeway simulation %s", simulation.uuid).
  • Leave all other lines as-is.
Suggested changeset 1
opendrift_leeway_webgui/leeway/tasks.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/opendrift_leeway_webgui/leeway/tasks.py b/opendrift_leeway_webgui/leeway/tasks.py
--- a/opendrift_leeway_webgui/leeway/tasks.py
+++ b/opendrift_leeway_webgui/leeway/tasks.py
@@ -53,7 +53,7 @@
         str(simulation.uuid),
         "--no-web",
     ]
-    print(" ".join(params))
+    logger.debug("Starting leeway simulation %s", simulation.uuid)
     with subprocess.Popen(
         params, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True
     ) as sim_proc:
EOF
@@ -53,7 +53,7 @@
str(simulation.uuid),
"--no-web",
]
print(" ".join(params))
logger.debug("Starting leeway simulation %s", simulation.uuid)
with subprocess.Popen(
params, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True
) as sim_proc:
Copilot is powered by AI and may make mistakes. Always verify output.
filename = os.path.join(settings.SIMULATION_ROOT, "input", url.split("/")[-1])
with open(filename, "wb") as f:
for chunk in response.iter_content(chunk_size=1024):
f.write(chunk)

Check failure

Code scanning / CodeQL

Clear-text storage of sensitive information High

This expression stores
sensitive data (private)
as clear text.
This expression stores
sensitive data (private)
as clear text.
This expression stores
sensitive data (private)
as clear text.
This expression stores
sensitive data (private)
as clear text.
This expression stores
sensitive data (private)
as clear text.
This expression stores
sensitive data (private)
as clear text.

Copilot Autofix

AI 5 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better weather & sea current data

2 participants