mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 22:40:01 -04:00
cull paths unlikely to escape & add strictRewrites flag
This commit is contained in:
parent
ba0aa479f0
commit
bdf5fd4f95
6 changed files with 25 additions and 7 deletions
|
@ -75,6 +75,7 @@ fn get_config(scramjet: &Object, url: &str) -> Config {
|
||||||
do_sourcemaps: get_flag(scramjet, url, "sourcemaps"),
|
do_sourcemaps: get_flag(scramjet, url, "sourcemaps"),
|
||||||
capture_errors: get_flag(scramjet, url, "captureErrors"),
|
capture_errors: get_flag(scramjet, url, "captureErrors"),
|
||||||
scramitize: get_flag(scramjet, url, "scramitize"),
|
scramitize: get_flag(scramjet, url, "scramitize"),
|
||||||
|
strict_rewrites: get_flag(scramjet, url, "strictRewrites"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,7 @@ fn dorewrite(source_text: &str) -> String {
|
||||||
capture_errors: true,
|
capture_errors: true,
|
||||||
do_sourcemaps: true,
|
do_sourcemaps: true,
|
||||||
scramitize: false,
|
scramitize: false,
|
||||||
|
strict_rewrites: false,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.as_slice(),
|
.as_slice(),
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub type EncodeFn = Box<dyn Fn(String) -> String>;
|
||||||
struct Rewriter {
|
struct Rewriter {
|
||||||
jschanges: Vec<JsChange>,
|
jschanges: Vec<JsChange>,
|
||||||
base: Url,
|
base: Url,
|
||||||
config: Config,
|
config: Confistrig,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
@ -52,6 +52,7 @@ pub struct Config {
|
||||||
pub capture_errors: bool,
|
pub capture_errors: bool,
|
||||||
pub scramitize: bool,
|
pub scramitize: bool,
|
||||||
pub do_sourcemaps: bool,
|
pub do_sourcemaps: bool,
|
||||||
|
pub strict_rewrites: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rewriter {
|
impl Rewriter {
|
||||||
|
@ -128,6 +129,18 @@ impl<'a> Visit<'a> for Rewriter {
|
||||||
return; // unwise to walk the rest of the tree
|
return; // unwise to walk the rest of the tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !self.config.strict_rewrites
|
||||||
|
&& !UNSAFE_GLOBALS.contains(&s.property.name.as_str())
|
||||||
|
{
|
||||||
|
if let Expression::Identifier(i) = &s.object {
|
||||||
|
// cull tree - this should be safe
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if let Expression::ThisExpression(_) = &s.object {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if self.config.scramitize
|
if self.config.scramitize
|
||||||
&& !matches!(s.object, Expression::MetaProperty(_))
|
&& !matches!(s.object, Expression::MetaProperty(_))
|
||||||
&& !matches!(s.object, Expression::Super(_))
|
&& !matches!(s.object, Expression::Super(_))
|
||||||
|
|
|
@ -45,12 +45,13 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
|
|
||||||
client.Proxy("Promise.prototype.catch", {
|
client.Proxy("Promise.prototype.catch", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
ctx.args[0] = new Proxy(ctx.args[0], {
|
if (ctx.args[0])
|
||||||
apply(target, thisArg, argArray) {
|
ctx.args[0] = new Proxy(ctx.args[0], {
|
||||||
// console.warn("CAUGHT PROMISE REJECTION", argArray);
|
apply(target, thisArg, argArray) {
|
||||||
Reflect.apply(target, thisArg, argArray);
|
// console.warn("CAUGHT PROMISE REJECTION", argArray);
|
||||||
},
|
Reflect.apply(target, thisArg, argArray);
|
||||||
});
|
},
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ export class ScramjetController {
|
||||||
serviceworkers: false,
|
serviceworkers: false,
|
||||||
naiiveRewriter: false,
|
naiiveRewriter: false,
|
||||||
captureErrors: true,
|
captureErrors: true,
|
||||||
|
strictRewrites: false,
|
||||||
syncxhr: false,
|
syncxhr: false,
|
||||||
cleanerrors: false,
|
cleanerrors: false,
|
||||||
scramitize: false,
|
scramitize: false,
|
||||||
|
|
1
src/types.d.ts
vendored
1
src/types.d.ts
vendored
|
@ -27,6 +27,7 @@ type ScramjetFlags = {
|
||||||
serviceworkers: boolean;
|
serviceworkers: boolean;
|
||||||
naiiveRewriter: boolean;
|
naiiveRewriter: boolean;
|
||||||
captureErrors: boolean;
|
captureErrors: boolean;
|
||||||
|
strictRewrites: boolean;
|
||||||
cleanerrors: boolean;
|
cleanerrors: boolean;
|
||||||
scramitize: boolean;
|
scramitize: boolean;
|
||||||
sourcemaps: boolean;
|
sourcemaps: boolean;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue