Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: respect explicit allowedOrigins configurations #255

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion packages/puppeteer/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ export function pageIsLoaded(): boolean {
}

export function configureAxe(config?: Axe.Spec): void {
window.axe.configure({
allowedOrigins: ['<unsafe_all_origins>']
});

if (config) {
window.axe.configure(config);
}

window.axe.configure({
allowedOrigins: ['<unsafe_all_origins>'],
branding: { application: 'axe-puppeteer' }
});
}
34 changes: 25 additions & 9 deletions packages/puppeteer/test/integration/doc-dylang.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('doc-dylang.html', function () {
before(async function () {
// const app: express.Application = express()
const app: express.Application = express();
app.use(express.static(path.resolve(__dirname, '..', 'fixtures')));
app.use(express.static(path.resolve(__dirname, '..', 'fixtures')));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting changes to the existing tests were recommended by npm run fmt when I ran it as part of validating the new test

this.server = createServer(app);
this.addr = await testListen(this.server);

Expand Down Expand Up @@ -63,20 +63,36 @@ describe('doc-dylang.html', function () {
expect(results.passes).to.have.lengthOf(0);
});


it('configures in nested frames', async function() {
await this.page.goto(this.fixtureFileURL('nested-frames.html'))
it('configures in nested frames', async function () {
await this.page.goto(this.fixtureFileURL('nested-frames.html'));

const results = await new AxePuppeteer(this.page)
.configure(await customConfig())
.withRules(['dylang'])
.analyze()
.analyze();

expect(results.violations.find((r: Axe.Result) => r.id === 'dylang'))
.to.not.be.undefined
expect(results.violations.find((r: Axe.Result) => r.id === 'dylang')).to.not
.be.undefined;
expect(results.violations.find((r: Axe.Result) => r.id === 'dylang'))
.to.have.property('nodes')
.and.to.have.lengthOf(4)
})
.and.to.have.lengthOf(4);
});

it('omits results from iframes forbidden by allowedOrigins', async function () {
await this.page.goto(this.fixtureFileURL('nested-frames.html'));

const config = await customConfig();
config.allowedOrigins = ['http://not-our-iframe.example.com'];

const results = await new AxePuppeteer(this.page)
.configure(config)
.withRules(['dylang'])
.analyze();

expect(results.violations.find((r: Axe.Result) => r.id === 'dylang')).to.not
.be.undefined;
expect(results.violations.find((r: Axe.Result) => r.id === 'dylang'))
.to.have.property('nodes')
.and.to.have.lengthOf(1); // omitting the 3 in disallowed iframe origins
});
});
3 changes: 2 additions & 1 deletion packages/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,11 @@ function reactAxe(
conf['disableOtherRules'] = true;
}

axeCore.configure({ allowedOrigins: ['<unsafe_all_origins>'] });
if (Object.keys(conf).length > 0) {
axeCore.configure(conf);
}
axeCore.configure({ allowedOrigins: ['<unsafe_all_origins>'] });

if (!_createElement) {
_createElement = React.createElement;

Expand Down
8 changes: 3 additions & 5 deletions packages/webdriverjs/src/axe-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ export default class AxeInjector {
private get script(): string {
return `
${this.axeSource}
${this.config ? `axe.configure(${this.config})` : ''}
axe.configure({
allowedOrigins: ['<unsafe_all_origins>'],
branding: { application: 'webdriverjs' }
})
axe.configure({ allowedOrigins: ['<unsafe_all_origins>'] });
${this.config ? `axe.configure(${this.config});` : ''}
axe.configure({ branding: { application: 'webdriverjs' } });
`;
}

Expand Down
25 changes: 25 additions & 0 deletions packages/webdriverjs/src/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ describe('@axe-core/webdriverjs', () => {
assert.equal(results.violations[0].nodes.length, 2);
});

it('should not find violations in iframes prohibited by allowedOrigins', async () => {
const config = {
...json,
allowedOrigins: ['http://not-our-iframe.example.com']
};

await driver.get(`${addr}/outer-configure-iframe.html`);
const results = await new AxeBuilder(driver)
.options({
rules: {
'landmark-one-main': { enabled: false },
'page-has-heading-one': { enabled: false },
region: { enabled: false },
'html-lang-valid': { enabled: false },
bypass: { enabled: false }
}
})
.configure(config)
.analyze();

assert.equal(results.violations[0].id, 'dylang');
// There is a second violation in a iframe which we should miss
assert.equal(results.violations[0].nodes.length, 1);
});

it('should find configured violations in all frames', async () => {
await driver.get(`${addr}/outer-configure-frame.html`);
const results = await new AxeBuilder(driver)
Expand Down