Skip to content

REFACTOR: Improve API and security in Desktop #5892

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

Merged
merged 27 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8398854
REFACTOR: Improve API and security in Desktop
SMoraisAnsys Mar 10, 2025
cf91289
chore: adding changelog file 5892.miscellaneous.md [dependabot-skip]
pyansys-ci-bot Mar 10, 2025
4260757
REFACTOR: Extend API in Design
SMoraisAnsys Mar 11, 2025
57a150b
TESTS: Clean up
SMoraisAnsys Mar 11, 2025
ff85635
TESTS: Fix removed fixture decorator
SMoraisAnsys Mar 11, 2025
e075f76
TESTS: Apply code review and remove direct call
SMoraisAnsys Mar 11, 2025
d801cd8
FIX(Desktop): Add back removed properties
SMoraisAnsys Mar 11, 2025
b066757
TESTS: Clean up
SMoraisAnsys Mar 11, 2025
10ca258
FIX: init desktop from design
SMoraisAnsys Mar 11, 2025
cd8aef5
REFACTOR: Extend subprocess checking
SMoraisAnsys Mar 14, 2025
5bb2b04
REFACTOR: add checking for subprocess calls
SMoraisAnsys Mar 17, 2025
2af0b1e
Merge branch 'main' into refact/desktop-to-deprecate-and-improve-sec
SMoraisAnsys Mar 17, 2025
5e2e7a7
REFACTOR: Simply reading
SMoraisAnsys Mar 17, 2025
5372bde
Merge branch 'main' into refact/desktop-to-deprecate-and-improve-sec
SMoraisAnsys Mar 26, 2025
5d8ddd0
REFACTOR: Continue refactoring
SMoraisAnsys Mar 26, 2025
96e1d94
DOCS: Add warning on method usage
SMoraisAnsys Mar 27, 2025
859b38d
Merge branch 'main' into refact/desktop-to-deprecate-and-improve-sec
SMoraisAnsys Mar 27, 2025
a600663
DOCS: Fix vale issues
SMoraisAnsys Mar 27, 2025
e4736c6
TESTS: Fix import issue
SMoraisAnsys Mar 27, 2025
f0663a7
DOCS: Fix vale issues
SMoraisAnsys Mar 27, 2025
5b9c5d7
FIX: Codacy issues
SMoraisAnsys Mar 27, 2025
ffbaf5d
TESTS: Extend testing coverage
SMoraisAnsys Mar 28, 2025
e990bbf
Apply suggestions from code review
SMoraisAnsys Mar 28, 2025
9d1f4dd
Merge branch 'main' into refact/desktop-to-deprecate-and-improve-sec
SMoraisAnsys Mar 28, 2025
731a007
Update doc/source/User_guide/index.rst
SMoraisAnsys Apr 1, 2025
e97b470
Merge branch 'main' into refact/desktop-to-deprecate-and-improve-sec
Samuelopez-ansys Apr 1, 2025
2f98223
DOCS: Fix typo
SMoraisAnsys Apr 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/5892.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve API and security in Desktop
8 changes: 8 additions & 0 deletions doc/source/User_guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ For end-to-end examples, see `Examples <https://examples.aedt.docs.pyansys.com>`

How to create and analyze EMIT designs.

.. grid-item-card:: Security considerations
:link: security_consideration
:link-type: doc
:margin: 2 2 0 0

Information on security considerations.

.. toctree::
:hidden:
:maxdepth: 2
Expand All @@ -95,3 +102,4 @@ For end-to-end examples, see `Examples <https://examples.aedt.docs.pyansys.com>`
files
postprocessing
emit_modeler
security_consideration
38 changes: 38 additions & 0 deletions doc/source/User_guide/security_consideration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Security considerations
=======================

This section provides information on security considerations for the use
of PyAEDT. It is important to understand the capabilities which PyAEDT
provides, especially when using it to build applications or scripts that
accept untrusted input.

.. _security_launch_aedt:

Launching AEDT
--------------

The :py:func:`.launch_aedt` and :py:func:`.launch_aedt_in_lsf` functions can be used
to launch AEDT. The executable which is launched is configured with the function
parameters, environment variables and the
`settings <https://aedt.docs.pyansys.com/version/stable/User_guide/settings.html>`_.
This may allow an attacker to launch arbitrary executables on the system. When
exposing the launch function to untrusted users, it is important to validate that
the executable path, environment variables (for example ``"ANSYSEM_ROOT"``,
``ANSYSEM_PY_CLIENT_ROOT`` and ``ANSYSEMSV_ROOT``) and PyAEDT settings are safe.
Otherwise, hard-code them in the application.

.. _security_ansys_cloud:

Retrieving Ansys Cloud information
----------------------------------

The :py:func:`.get_cloud_job_info` and :py:func:`.get_available_cloud_config`
functions can be used to retrieve information related to Ansys Cloud.
The executable which is launched is configured with the function
parameters and the AEDT installation that is detected. Since finding the AEDT
installation path is based of environment variables, this may allow an attacker
to launch arbitrary executables on the system. When exposing the launch function
to untrusted users, it is important to validate that environment variables like
``"ANSYSEM_ROOT"``, ``ANSYSEM_PY_CLIENT_ROOT`` and ``ANSYSEMSV_ROOT`` are safe.
Otherwise, hard-code them in the application.

2 changes: 2 additions & 0 deletions doc/styles/config/vocabularies/ANSYS/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ busbars
Bz
CHECKIN
[Cc]ircuit
[Cc]loud
codecov
(?i)Com
COM interface
Expand Down Expand Up @@ -97,6 +98,7 @@ subcircuit
[Tt]oolkit [Mm]anager
Twin Builder
Uncomment
untrusted
utils
vias
manual_settings
Expand Down
38 changes: 22 additions & 16 deletions src/ansys/aedt/core/application/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
from ansys.aedt.core.application.design_solutions import solutions_defaults
from ansys.aedt.core.application.variables import DataSet
from ansys.aedt.core.application.variables import VariableManager
from ansys.aedt.core.desktop import _init_desktop_from_design
from ansys.aedt.core.desktop import Desktop
from ansys.aedt.core.desktop import exception_to_desktop
from ansys.aedt.core.generic.constants import AEDT_UNITS
from ansys.aedt.core.generic.constants import unit_system
Expand Down Expand Up @@ -196,7 +196,7 @@ def __init__(
self._design_datasets: List = []
self.close_on_exit: bool = close_on_exit
self._desktop_class = None
self._desktop_class = _init_desktop_from_design(
self._desktop_class = self.__init_desktop_from_design(
version,
non_graphical,
new_desktop,
Expand Down Expand Up @@ -4233,6 +4233,12 @@ def edit_notes(self, text):
self.odesign.EditNotes(text)
return True

@classmethod
def __init_desktop_from_design(cls, *args, **kwargs):
"""Internal instantiation of the ``Desktop`` class."""
Desktop._invoked_from_design = True
return Desktop(*args, **kwargs)


class DesignSettings:
"""Get design settings for the current AEDT app.
Expand All @@ -4246,20 +4252,6 @@ def __init__(self, app):
self._app: Any = app
self.manipulate_inputs: Optional[DesignSettingsManipulation] = None

@property
def design_settings(self) -> Optional[Any]:
"""Design settings."""
try:
return self._app.odesign.GetChildObject("Design Settings")
except GrpcApiError: # pragma: no cover
self._app.logger.error("Failed to retrieve design settings.")
return None

@property
def available_properties(self) -> List[str]:
"""Available properties names for the current design."""
return [prop for prop in self.design_settings.GetPropNames() if not prop.endswith("/Choices")]

def __repr__(self) -> str:
lines = ["{"]
for prop in self.available_properties:
Expand Down Expand Up @@ -4294,6 +4286,20 @@ def __getitem__(self, key: str) -> Optional[Any]:
def __contains__(self, item: str) -> bool:
return item in self.available_properties

@property
def design_settings(self) -> Optional[Any]:
"""Design settings."""
try:
return self._app.odesign.GetChildObject("Design Settings")
except GrpcApiError: # pragma: no cover
self._app.logger.error("Failed to retrieve design settings.")
return None

@property
def available_properties(self) -> List[str]:
"""Available properties names for the current design."""
return [prop for prop in self.design_settings.GetPropNames() if not prop.endswith("/Choices")]


class DesignSettingsManipulation:
@abstractmethod
Expand Down
Loading
Loading