Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2f72b46
feat(fetchAllTemplates) implemented user authentication and authorisa…
Ajith-Penmatsa-GGL Dec 11, 2025
8fda325
feat(dashboard): implement conditional 'Create model from Template' a…
Ajith-Penmatsa-GGL Dec 11, 2025
edb981a
feat: Fetched templates from metadata objects and rendered in ui
Ajith-Penmatsa-GGL Dec 15, 2025
aabfb4d
feat: added to feature to export templates from a model
Ajith-Penmatsa-GGL Dec 15, 2025
202e650
added crud functionality for the admin
Ajith-Penmatsa-GGL Dec 23, 2025
83a2048
feat: add template bootstrapping and unified search
Ajith-Penmatsa-GGL Jan 18, 2026
009ee3c
refactored templates controller
Ajith-Penmatsa-GGL Jan 26, 2026
58273da
added documentation and fixed eslint errors
Ajith-Penmatsa-GGL Jan 29, 2026
be46058
cleaning up docs and fetch all tempaltes logic
Ajith-Penmatsa-GGL Jan 30, 2026
1901286
cleaned up some unnecessary commetns
Ajith-Penmatsa-GGL Jan 30, 2026
2cf4959
write main process functions to set template folder path
Ajith-Penmatsa-GGL Feb 1, 2026
85d7f0f
changed main process operations to empalte and wired up round trip
Ajith-Penmatsa-GGL Feb 1, 2026
57b90ee
added a feature to save a tempalte path in desktop
Ajith-Penmatsa-GGL Feb 4, 2026
ba2af06
mvp of templates feature for desktop
Ajith-Penmatsa-GGL Feb 8, 2026
2f64606
custom dialog box for setting up template folder
Ajith-Penmatsa-GGL Feb 8, 2026
2fbed21
made changes in status's for template gallery and manage tempaltes so…
Ajith-Penmatsa-GGL Feb 12, 2026
da8e8b7
removed admin checks from endpoints and added it to middleware
Ajith-Penmatsa-GGL Mar 8, 2026
0766e45
removed unused i8n strings
Ajith-Penmatsa-GGL Mar 8, 2026
489ce4e
synced up branch with origin main
Ajith-Penmatsa-GGL Mar 9, 2026
6437c5b
added documentation for desktop version of the tempaltes feature
Ajith-Penmatsa-GGL Mar 12, 2026
baad334
added test suites to increase coverage
Ajith-Penmatsa-GGL Mar 15, 2026
2549421
added new test suits
Ajith-Penmatsa-GGL Mar 15, 2026
f828598
synced with owasp main branch
Ajith-Penmatsa-GGL Mar 16, 2026
5c53b33
renamed ipcMain listner to ipcMainAPI
Ajith-Penmatsa-GGL Mar 19, 2026
4033c38
removed unused documentation
Ajith-Penmatsa-GGL Mar 22, 2026
8698c9c
fixed markdown lint errors on template and configuration documentation
Ajith-Penmatsa-GGL Mar 22, 2026
989994e
fixed spellings to pass the spellcheck in pull request pipeline
Ajith-Penmatsa-GGL Mar 22, 2026
88d8e6b
removed redundant image
Ajith-Penmatsa-GGL Apr 6, 2026
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
Binary file added docs/assets/images/export-template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/folder-setup-dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/intialise-templates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/images/template-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions docs/configure/local.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,50 @@ or if using Windows:

- `docker run -d -p 8080:3000 -v %CD%/test.env:/app/.env owasp/threat-dragon:stable`

## Configuring Templates for Desktop

Navigate to the cog icon in the navigation bar and click **Manage Templates**.

![Manage template image]({{ '/assets/images/manage-template.png'
| relative_url }}){: style="max-width: 400px; width: 100%;" }

If templates have not been configured before, you will be presented with a setup dialog offering three options:

![Folder Setup Dialog Box]({{ '/assets/images/folder-setup-dialog.png'
| relative_url }}){: style="max-width: 400px; width: 100%;" }

- **Use default location** — creates a `templates` folder in the application data directory
(`AppData/Roaming/Threat Dragon/templates` on Windows)
- **Choose custom location** — opens a folder browser so you can select any folder on your filesystem
- **Select existing template folder** — point to a folder that already contains a `template_info.json` index file

For the default and custom location options, Threat Dragon will automatically create a `template_info.json`
index file in the selected folder if one does not already exist.

For the existing folder option, the folder must already contain a valid `template_info.json` file.
If the file is not found, setup will fail with an error.

### Folder Structure

All template files are stored flat in the configured folder alongside the index file:

```plaintext
templates/
├── template_info.json ← index file listing all templates
├── my-template-abc123.json ← template model file
└── another-template-xyz.json
```

The `template_info.json` file is managed automatically by Threat Dragon — you do not need to edit it manually.

### Changing the Template Folder Location

The configured template folder path is persisted in `AppData/Roaming/Threat Dragon/templates-path.txt`.
To change the template storage location, delete this file and restart Threat Dragon and
you will be prompted to configure a new location on next launch.

Note that templates from the previous folder will not be migrated automatically.

### Example production local environment

Important: this example file contains test values, do not use these values for anything other than short-term tests.
Expand Down
153 changes: 145 additions & 8 deletions docs/usage/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ quickly create new threat models based on pre-defined structures.

**Note**: The template feature is currently available for GitHub repositories and for local users
who have templates stored in their local file system. Support for Atlassian Bitbucket, GitLab, Google Drive,
and desktop is coming in future releases.
is coming in future releases.

## Create a new model from a template

Expand Down Expand Up @@ -50,7 +50,7 @@ where you can enter general information about your model.
The template's diagrams, components, and threats will already be populated as a starting point.
The name that you provide for the model will be used as the file name within the repository.

## Loading a template from a local file
### Loading a template from a local file

In addition to organisation templates, you can also start from a local template file.
This is useful when you have received a template file from a colleague.
Expand All @@ -71,10 +71,7 @@ The imported template's diagrams, components, and threats will be used as a star
to your organisation's template repository. Only administrators can add templates to
the shared template gallery.

## Exporting an existing model as a template

**Note** : This feature is currently only available for web-based local sessions and GitHub authenticated
sessions. Support for additional providers will be added in a future releases.
### Exporting an existing model as a template

If you have created a threat model that would be useful as a template for others,
you can export it as a template file that can be shared or imported later.
Expand Down Expand Up @@ -106,7 +103,7 @@ The exported template file can then be:
**Note**: The export removes any organisation-specific information (such as repository paths)
and generates new unique identifiers, making it suitable for use as a reusable template.

## Managing Templates (Administrators)
### Managing Templates (Administrators)

Users with **push** or **admin** permissions on the template repository (`GITHUB_CONTENT_REPO`)
are considered administrators and can manage the organisation's shared template gallery.
Expand All @@ -119,7 +116,7 @@ which takes you to the Manage Templates page where you can add, edit, and delete
| relative_url }}){: style="max-width: 400px; width: 100%;" }

For information on configuring the template repository, see the
[GitHub configuration guide](../configure/github.md#template-repository-configuration).
[GitHub configuration guide]({{ '/configure/github.html#template-repository-configuration'| relative_url }}).

### Bootstrapping the Template Repository

Expand Down Expand Up @@ -179,3 +176,143 @@ template are not affected, but the template will no longer be available for crea
**Session timeout**: When logging in to an external drive or repository, be aware that sessions
can time out. This timeout length varies by provider; if this is a problem, keep the session
alive using a tab in the same browser window.

## Using the Desktop application

![Start Button]({{ '/assets/images/start.png'| relative_url }})

The threat dragon desktop application can be configured with templates stored in local file system.

For information on how to configure templates in your desktop deployment, see the
[Local configuration guide]({{ '/configure/local.html#configuring-templates-for-desktop' | relative_url }})

![Template button image]({{ '/assets/images/template-button.png'
| relative_url }}){: .float-right style="max-width: 170px; width: 100%;" }

To create a new threat model from a template, go to the Welcome page and click the
**Create model from a Template** button.

You will then be presented with the Template Gallery showing all available templates.
Browse or search for a template that fits your needs, then click on the template card to select it.

![Template Gallery]({{ '/assets/images/template-gallery.png'
| relative_url }}){: style="max-width: 500px; width: 100%;" }

After selecting a template, you will be taken to the threat model edit screen.
The template's diagrams, components, and threats will be pre-populated,
but metadata fields such as owner, reviewer, and contributors will be empty for you to fill in.

### Loading a template from a file

In addition to templates stored in your configured folder, you can also load a template directly
from any file on your filesystem. This is useful when you have received a template file from a colleague
that you want to use as a one-off starting point without adding it to your gallery.

**Note**: Template files use a different schema to standard threat model files and are not interchangeable.
To use an existing model as a starting point, first export it as a template using the **Export as Template** option.

From the Template Gallery, click the **Start from a Local Template** button to browse for a template file.
![Local template image]({{ '/assets/images/local-template.png'
| relative_url }}){: style="max-width: 500px; width: 100%;" }

The file will be validated to ensure it is a properly formatted Threat Dragon template.
Once loaded, you will be taken to the threat model edit screen with the template's diagrams,
components,and threats pre-populated.

**Note**: This creates a new model based on the selected file. It does not add the template
to your configured template folder.

### Exporting an existing model as a template on Desktop

If you have created a threat model that would be useful as a template for others,
you can export it as a template file that can be shared or imported later.

From your threat model's details page, click on the manage dropdown and select **Export as Template**.
You will be taken to the export template page where you can review and customise the template details.

![Export template image]({{ '/assets/images/export-template-button.png'
| relative_url }}){: style="max-width: 400px; width: 100%;" }

![Export template page]({{ '/assets/images/export-template-page.png'
| relative_url }}){: style="max-width: 1000px; width: 100%;" }

On the export template page, you can:

- Review the template name and description
- Add or modify tags for easier searching

Once you are satisfied with the template details, click **Save Template** to download the
template file to your local filesystem.

The exported template file can then be:

- Shared directly with colleagues so they can use it as a one-off starting point, without needing to add it to their gallery
- Imported into your own template gallery using the 'Manage Templates' portal.
- Used as a local backup or starting point for future models

**Note**: The export removes any model-specific information and generates new unique identifiers,
making it suitable for use as a reusable template.

### Managing Templates

On the desktop application, all users have full administrator access to the template gallery.

Click the **cog icon** in the navigation bar and select **Manage Templates** to open the
Manage Templates page,where you can add, edit, and delete templates.

![Manage template image]({{ '/assets/images/manage-template.png'
| relative_url }}){: style="max-width: 400px; width: 100%;" }

**Note**: You can only add, edit, or delete templates if you have write access to the configured template folder.
If the folder is read-only, the Manage Templates page will open in read-only mode and modification options will be hidden.

![Manage template image]({{ '/assets/images/read-only-templates-portal.png'
| relative_url }}){: style="max-width: 700px; width: 100%;"}

For information on configuring the template folder, see the
[Desktop Template Configuration Guide]({{ '/configure/local.html#configuring-templates-for-desktop' | relative_url }}).

### Bootstrapping the Template Folder

On the desktop application, template storage is initialised automatically when you configure a folder location.
Simply navigate to Manage Templates, select a setup option, and Threat Dragon will create the template_info.json
index file in the chosen folder automatically.

No separate initialisation step is required.

### Importing Templates to the Gallery on Desktop

1. Obtain a template file (either exported from an existing model or received from a colleague)
2. Navigate to the Manage Templates portal
3. Click the **Add New Template** button
![import-templates]({{ '/assets/images/import-template-button.png'
| relative_url }}){: style="max-width: 170px; width: 100%;"}
4. Select the template file from your local filesystem

The template will now appear in the Template Gallery.

### Updating Template Metadata on Desktop

You can update a template's name, description, or tags without modifying the template content.

1. Navigate to the Manage Templates page
2. Find the template you want to update
3. Click the kebab menu on the template card and select **Edit**
4. Modify the name, description, or tags as needed

![Kebab-Menu]({{ '/assets/images/kebab-menu.png' | relative_url }})

![Edit-Template]({{ '/assets/images/edit-template.png'
| relative_url }}){: style="max-width: 400px; width: 100%;" }

### Deleting Templates on Desktop

You can delete templates from your template gallery.

1. Navigate to the Manage Templates page
2. Find the template you want to delete
3. Click the kebab menu on the template card and select **Delete**
4. Confirm the deletion

**Warning**: Deleting a template cannot be undone. Existing threat models created from the
template are not affected, but the template will no longer be available for creating new models.
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions td.server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion td.server/src/config/bearer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ const middleware = (req, res, next) => {
}
};

const adminMiddleware = (req, res, next) => {
if (!req.user?.isAdmin) {
logger.warn(`User ${req.user?.id} attempted to access admin resource ${req.url}`);
return errors.forbidden(res, logger);
}
return next();
};

export default {
middleware
middleware,
adminMiddleware
};
Loading