Skip to content

Commit

Permalink
Merge branch 'main' into ernesto/new-stable-release
Browse files Browse the repository at this point in the history
  • Loading branch information
gnapse committed Aug 13, 2024
2 parents 4c2ba12 + 0950e92 commit edadaa8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/ui-extensions-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@doist/ui-extensions-core",
"version": "4.2.0",
"version": "4.2.1",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
4 changes: 3 additions & 1 deletion packages/ui-extensions-core/src/ui-helpers/card-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { type DoistCardVersion, DoistCard } from '../doist-card'
import { DoistCard } from '../doist-card'

import type { DoistCardVersion } from '../doist-card'

/**
* Creates an empty DoistCard
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-extensions-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"peerDependencies": {
"@doist/reactist": "^25.0.0",
"@doist/ui-extensions-core": "^4.1.1",
"@doist/ui-extensions-core": "^4.2.0",
"adaptivecards": "^2.9.0",
"react": "^17.0.0 || ^18.0.0",
"react-dom": "^17.0.0 || ^18.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ export function registerMarkdownParser(markdownParser: (text: string) => string)
}
}

/**
* Protects against XSS attacks by validating the URL.
* @param url
* @returns
*/
function isValidUrl(url: string): boolean {
try {
// Parse the URL using the URL constructor
const parsedUrl = new URL(url)

// Check for allowed protocols
if (parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:') {
return true
} else {
return false
}
} catch {
// If URL constructor throws an error, it's an invalid URL
return false
}
}

/**
* To support markdown, register a markdown parser via `registerMarkdownParser`
* @see registerMarkdownParser
Expand Down Expand Up @@ -97,7 +119,7 @@ export function AdaptiveCardRenderer({
try {
const inputs = adaptiveCard.getAllInputs()
const inputsObject = getInputObject(inputs)
if (action instanceof OpenUrlAction && action.url) {
if (action instanceof OpenUrlAction && action.url && isValidUrl(action.url)) {
window.open(action.url, '_blank')
} else if (action instanceof ClipboardAction && action.text) {
clipboardHandler(action.text)
Expand Down

0 comments on commit edadaa8

Please sign in to comment.