Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
build: skip validation of internal calls (#122)
Browse files Browse the repository at this point in the history
* build:  skip validation of internal calls

seia-soto/userscripts@364e979#diff-c6e4dc7a836563ce0dfea577b8fcea8f36c0d4ef78ad45bc1720d6c8e3180d9eR112

Co-authored-by: HoJeong Go <[email protected]>

* chore: upddate version

* build userscript

---------

Co-authored-by: HoJeong Go <[email protected]>
  • Loading branch information
piquark6046 and seia-soto authored Apr 6, 2024
1 parent 22eaff4 commit e4abfc4
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 32 deletions.
10 changes: 5 additions & 5 deletions microShield.user.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "microshield",
"version": "4.0.0",
"version": "4.1.0",
"description": "",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion sources/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// @downloadURL https://cdn.jsdelivr.net/gh/List-KR/microShield@latest/microShield.user.js
// @license Apache-2.0
//
// @version 4.0.0
// @version 4.1.0
// @author PiQuark6046 and contributors
//
// @match *://ygosu.com/*
Expand Down
5 changes: 2 additions & 3 deletions sources/src/adshield/resources.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {UnprotectedFetch} from '../utils/secret.js'
import {GetRandomAdShieldHost} from './validators.js'

export const GetCachableHtml = async (Url: string) => {
const ResponseRaw = await UnprotectedFetch(Url, {
const ResponseRaw = await fetch(Url, {
cache: 'force-cache'
})
const Text = await ResponseRaw.text()
Expand All @@ -15,7 +14,7 @@ export const GetCachableHtml = async (Url: string) => {
}

export const GetResourceToken = async (ScriptUrl: string) => {
const ResponseRaw = await UnprotectedFetch(ScriptUrl, {
const ResponseRaw = await fetch(ScriptUrl, {
cache: 'force-cache'
})
const Text = await ResponseRaw.text()
Expand Down
11 changes: 3 additions & 8 deletions sources/src/adshield/validators.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import cryptoRandomString from 'crypto-random-string'
import {JustifyCallStack} from '../utils/call-stack.js'
import {HasSubstringSetsInString} from '../utils/string.js'

export const AdshieldDomains = [
Expand Down Expand Up @@ -27,16 +26,12 @@ const AdshieldDomainsize = AdshieldDomains.length
// eslint-disable-next-line no-bitwise
export const GetRandomAdShieldHost = () => AdshieldDomains[(Number(cryptoRandomString({length: 16, type: 'numeric'})) * 0.0000000000000001 * AdshieldDomainsize) >>> 0]

export const IsAdShieldCall = (Trace = JustifyCallStack()) => {
if (Trace.length === 0) {
return false
}

if (HasSubstringSetsInString(Trace[Trace.length - 1], AdshieldDomains)) {
export const IsAdShieldCall = (LastLine: string) => {
if (HasSubstringSetsInString(LastLine, AdshieldDomains)) {
return true
}

const Url = new URL(Trace[Trace.length - 1])
const Url = new URL(LastLine)

if (Url.hostname !== location.hostname && Url.pathname === '/loader.min.js') {
return true
Expand Down
2 changes: 2 additions & 0 deletions sources/src/loaders/ztinywave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ export const Tinywave = async () => {
void InsertEntities(PrivateEntities)

Entities.push(...PublicEntities, ...PrivateEntities)

return Entities
})

Debug('sources resolves', await Promise.allSettled(SourcesResolves))
Expand Down
13 changes: 13 additions & 0 deletions sources/src/utils/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ export const TryCachedEntities = async () => {
if ((Date.now() - Data.CreatedAt) > 1000 * 60 * 60 * 24 * 30) {
throw new Error('The cached entities are too old!')
}

const TotalEntityLength = Data.Entities.reduce((State, Entity) => {
if (Entity.Type === EntityTypes.Head) {
return State + Entity.Html.length
}

return State
}, 0)

if (!TotalEntityLength) {
throw new Error('The cached entities has no content!')
}


Debug('restoring cached entities data=', Data)

Expand Down
27 changes: 13 additions & 14 deletions sources/src/utils/secret.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cryptoRandomString from 'crypto-random-string'
import {AdshieldKeywords, IsAdShieldCall} from '../adshield/validators.js'
import {Config} from '../config.js'
import {GenerateCallStack} from './call-stack.js'
import {GenerateCallStack, JustifyCallStack} from './call-stack.js'
import {CreateDebug} from './logger.js'
import {HasSubstringSetsInString} from './string.js'

Expand Down Expand Up @@ -41,7 +41,14 @@ export const ProtectFunction = <F extends Fomulate>(F: F, Options: ProtectedFunc
throw new Error()
}

if (IsAdShieldCall()) {
const JustifiedCallStack = JustifyCallStack()
const LastLine = JustifiedCallStack[JustifiedCallStack.length - 1]

if (LastLine === undefined || LastLine.startsWith('chrome') || LastLine.startsWith('webkit') || LastLine.startsWith('moz')) {
return false
}

if (IsAdShieldCall(LastLine)) {
E()
}

Expand Down Expand Up @@ -82,8 +89,6 @@ export const ProtectFunction = <F extends Fomulate>(F: F, Options: ProtectedFunc
}
})

export const UnprotectedFetch = fetch

export const ProtectedDescriptors = new Set<unknown>()

export const ProtectDescriptors = <T extends ArbitaryObject, K extends keyof T>(O: T, Key: K, NewProperty: T[K]) => {
Expand All @@ -107,24 +112,18 @@ export const ProtectDescriptors = <T extends ArbitaryObject, K extends keyof T>(
]
})

ProtectedDescriptors.add(DefineProperties)
ProtectedDescriptors.add(DefineProperty)
ProtectedDescriptors.add(DefineProperties)

Object.defineProperty(Win.Object, 'defineProperty', {
get() {
return DefineProperty
}
value: DefineProperty
})
Object.defineProperties(Win.Object, {
defineProperty: {
get() {
return DefineProperty
}
value: DefineProperty
},
defineProperties: {
get() {
return DefineProperties
}
value: DefineProperties
}
})
}
Expand Down

0 comments on commit e4abfc4

Please sign in to comment.