Skip to content

Commit 66a4dcb

Browse files
authored
issue #1285 fix sanitize-html build (#1286)
* #1285 use webpack for sanitize-html build * #1285 update sanitize-html imports
1 parent 578f8aa commit 66a4dcb

File tree

7 files changed

+52605
-32272
lines changed

7 files changed

+52605
-32272
lines changed

Core/source/platform/xss.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type Transformer = (tagName: string, attribs: Attributes) => Tag;
66

77
export type SanitizeImgHandling = 'IMG-DEL' | 'IMG-KEEP' | 'IMG-TO-LINK';
88

9-
declare const dereq_html_sanitize: (dirty: string, opts?: {
9+
declare const dereq_sanitize_html: (dirty: string, opts?: {
1010
allowedTags?: string[],
1111
selfClosing?: string[],
1212
exclusiveFilter?: (frame: { tag: string, attribs: Attributes, text: string, tagPosition: number }) => boolean,
@@ -47,7 +47,7 @@ export class Xss {
4747
public static htmlSanitizeKeepBasicTags = (dirtyHtml: string, imgToLink?: SanitizeImgHandling): string => {
4848
const imgContentReplaceable = `IMG_ICON_${Str.sloppyRandom()}`;
4949
let remoteContentReplacedWithLink = false;
50-
let cleanHtml = dereq_html_sanitize(dirtyHtml, {
50+
let cleanHtml = dereq_sanitize_html(dirtyHtml, {
5151
allowedTags: Xss.ALLOWED_BASIC_TAGS,
5252
allowedAttributes: Xss.ALLOWED_ATTRS,
5353
allowedSchemes: Xss.ALLOWED_SCHEMES,
@@ -85,7 +85,7 @@ export class Xss {
8585
if (remoteContentReplacedWithLink) {
8686
cleanHtml = `<font size="-1" color="#31a217" face="monospace">[remote content blocked for your privacy]</font><br /><br />${cleanHtml}`;
8787
// clean it one more time in case something bad slipped in
88-
cleanHtml = dereq_html_sanitize(cleanHtml, { allowedTags: Xss.ALLOWED_BASIC_TAGS, allowedAttributes: Xss.ALLOWED_ATTRS, allowedSchemes: Xss.ALLOWED_SCHEMES });
88+
cleanHtml = dereq_sanitize_html(cleanHtml, { allowedTags: Xss.ALLOWED_BASIC_TAGS, allowedAttributes: Xss.ALLOWED_ATTRS, allowedSchemes: Xss.ALLOWED_SCHEMES });
8989
}
9090
cleanHtml = cleanHtml.replace(new RegExp(imgContentReplaceable, 'g'), `<font color="#D14836" face="monospace">[img]</font>`);
9191
return cleanHtml;
@@ -106,7 +106,7 @@ export class Xss {
106106
let text = html.split(br).join('\n').split(blockStart).filter(v => !!v).join('\n').split(blockEnd).filter(v => !!v).join('\n');
107107
text = text.replace(/\n{2,}/g, '\n\n');
108108
// not all tags were removed above. Remove all remaining tags
109-
text = dereq_html_sanitize(text, {
109+
text = dereq_sanitize_html(text, {
110110
allowedTags: ['img', 'span'],
111111
allowedAttributes: { img: ['src'] },
112112
allowedSchemes: Xss.ALLOWED_SCHEMES,
@@ -116,7 +116,7 @@ export class Xss {
116116
},
117117
}
118118
});
119-
text = dereq_html_sanitize(text, { allowedTags: [] }); // clean it one more time to replace leftover spans with their text
119+
text = dereq_sanitize_html(text, { allowedTags: [] }); // clean it one more time to replace leftover spans with their text
120120
text = text.trim();
121121
if (outputNl !== '\n') {
122122
text = text.replace(/\n/g, outputNl);

Core/source/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'use strict';
44

55
// @ts-ignore - this way we can test the Xss class directly as well
6-
global.dereq_html_sanitize = require("sanitize-html");
6+
global.dereq_sanitize_html = require("sanitize-html");
77
// @ts-ignore - this way we can test ISO-2201-JP encoding
88
global.dereq_encoding_japanese = require("encoding-japanese");
99
(global as any)["emailjs-mime-builder"] = require('../../source/lib/emailjs/emailjs-mime-builder');

Core/tooling/fix-bundles.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ for (const filename of fs.readdirSync(bundleRawDir)) {
2626
// copy raw to flowcrypt-bundle
2727
fs.copyFileSync(`${bundleRawDir}/entrypoint-bare.js`, `${bundleDir}/entrypoint-bare-bundle.js`);
2828

29-
const sanitizeHtmlDist = './node_modules/sanitize-html/index.js';
29+
const sanitizeHtmlDist = `${bundleWipDir}/sanitize-html.js`;
3030

3131
// copy wip to html-sanitize-bundle
3232
fs.writeFileSync(
3333
`${bundleDir}/bare-html-sanitize-bundle.js`,
34-
`${fs.readFileSync(sanitizeHtmlDist).toString()}\nconst dereq_html_sanitize = window.sanitizeHtml;\n`
34+
fs.readFileSync(sanitizeHtmlDist).toString()
3535
);
3636

3737
// copy zxcvbn, only used for bare (iOS) because zxcvbn-ios is not well maintained: https://github.com/dropbox/zxcvbn-ios/issues

Core/webpack.bare.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module.exports = {
55
entry: {
66
'entrypoint-bare': './build/ts/entrypoint-bare.js',
77
'bare-asn1': './node_modules/asn1.js/lib/asn1.js',
8-
'bare-encoding-japanese': './node_modules/encoding-japanese/encoding.js'
8+
'bare-encoding-japanese': './node_modules/encoding-japanese/encoding.js',
9+
'sanitize-html': './node_modules/sanitize-html/index.js'
910
},
1011
output: {
1112
path: __dirname + '/build/bundles/raw',

FlowCrypt/Core/Core.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,13 @@ actor Core: KeyDecrypter, KeyParser, CoreComposeMessageType {
204204
context?.setObject(CoreHost(), forKeyedSubscript: "coreHost" as (NSCopying & NSObjectProtocol))
205205
context!.exceptionHandler = { _, exception in
206206
guard let exception = exception else { return }
207+
208+
let line = exception.objectForKeyedSubscript("line").toString()
209+
let column = exception.objectForKeyedSubscript("column").toString()
210+
let location = [line, column].compactMap { $0 }.joined(separator: ":")
211+
207212
let logger = Logger.nested(in: Self.self, with: "Js")
208-
logger.logWarning("\(exception)")
213+
logger.logWarning("\(exception), \(location)")
209214
}
210215
context!.evaluateScript("const APP_VERSION = 'iOS 0.2';")
211216
context!.evaluateScript(jsFileSrc)

FlowCrypt/Core/CoreHost.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import SwiftyRSA // for rsa
2323
func clearTimeout(_ identifier: String)
2424

2525
func handleCallback(_ endpointKey: String, _ string: String, _ data: [UInt8])
26+
func log(_ message: String)
2627
}
2728

2829
var timers = [String: Timer]()
@@ -125,6 +126,10 @@ final class CoreHost: NSObject, CoreHostExports {
125126
}
126127
}
127128

129+
func log(_ message: String) {
130+
Logger.logDebug(message)
131+
}
132+
128133
@objc func callJsCb(_ timer: Timer) {
129134
let callback = (timer.userInfo as! JSValue)
130135
callback.call(withArguments: nil)

0 commit comments

Comments
 (0)